Why is this not working.
I want to track conversion on my online shop when somebody buys something successfully.
This is the code
<script async src="https://www.googletagmanager.com/gtag/js?id=xxx"></script>
<script>
{# ga preloader #}
window['GoogleAnalyticsObject'] = 'ga';
window['ga'] = window['ga'] || function() {
(window['ga'].q = window['ga'].q || []).push(arguments)
};
{# default google analytics #}
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'xxxx');
ga('require', 'ecommerce');
</script>
And then according to the docs on the order success page there is this:
<script>
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'transaction_id': 'xxxx',
'affiliation': 'Online Store',
'value': '100',
'currency': 'USD',
'items': [{
'item_name': 'T-Shyrt X',
'item_id': 'tshirtx',
'price': '50',
'item_brand': 'Yadayada',
'quantity': '1'
}, {
'item_name': 'T-Shyrt Y',
'item_id': 'tshirtx',
'price': '50',
'item_brand': 'Yadayada',
'quantity': '1'
}]
}
});
</script>
I've let it run vor 72 hours and had a few orders in that time. Nothing showed up so far.
You are mixing ga
and gtag
code.
Also the documentation you have provided refers to Google Tag Manager, while to you it appears that you are not or are using since you have the explicit code in the Analytics library page (apart from the fact that you are mixing different codes).
If you use the code in page instead of GTM, you have to use gtag.js
code and follow this documentation: