Dear Piwik Pro-Community,
I’d like to use an existing GA3 (Universal Analytics) or GA4 dataLayer for Piwik. Unfortunately both doesn’t work yet. For GA4 the reason might be that it’s in the second level of the DL. But what might be the reason for the DL of GA3?
Here is how the dataLayer look like (NAME is just a placeholder for our example)
<script>
var dataLayer = window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'confirmationPage',
'custom1': '1', 'currencyCode': 'EUR',
'transactionId': '907152', 'transactionAffiliation': 'Buchung', 'transactionTotal': 185, 'transactionTax': 0,
'transactionShipping': 0,
'transactionProducts': [{"sku":"NAME [1]","name":"NAME","category":"PKW","price":185,"quantity":1}],
});
// New Data-Layer
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'transaction_id': '12346',
'affiliation': 'Buchung',
'value': '185',
'tax': '0',
'shipping': '0',
'currency': 'EUR',
'coupon': '',
'items': [
{
"item_name": "NAME",
"item_id": "NAME [1]",
"price": 185,
"item_category": "PKW",
"quantity": 1
}
],
},
});
</script>
The Piwik tag to fetch the data of the GA3-DL is:
(function () {
var products = {{ transactionProducts }};
products.forEach(function(product){
_paq.push(["addEcommerceItem", product.sku, product.name, product.category, product.price, product.quantity]);
});
_paq.push(["trackEcommerceOrder", {{ transactionID }}, {{ transactionTotal }}, "0", {{ transactionTax }}, {{ transactionShipping }}, "0"]);
})();
This tag is fired when DOM is ready and with a regex for the page url.
And yes, Administration > Reports > Ecommerce is activated
In the Debug view of the Piwik Tag Manager I can see, that the E-Commerce-Tag is fired on the order confirmation page. But unfortunately the variables are empty. And in the Tracker debugger of Piwik Analytics the purchase event doesn’t appear.
I know about one handicap:
Unfortunately our DL is in the body of the page. I know that it should be placed before the Piwik PRO’s container code, which is in the head of the page.
Is there a solution to use nevertheless this DL?
Best regards
Jürgen