I am trying to implement the enhanced ecommerce plugin. but my ecommerce data is not reflecting in the `Google Analytics web interface.
Below is my script I included in the header page.
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxxx-1', 'auto',{'name': 'newTracker'});
ga('newTracker.require', 'ec');
ga('ec:addPromo', {
'id': 'xyz', // Promotion ID - Required Type: string
'name': 'test', // Promotion Name - Type: string
'creative':'', // Creative ad used for promotion - Type: string
'position':'' // Position of the creative ad - Type: string
});
ga('newTracker.send', 'pageview');
Above is debug output. I have old plugin use a different ID and new plugin use a different ID. Both are in different js files. but trigger same time with user events. I see error below aborting hit. I am not sure is this the old or new plugin aborting the hit or should I ignore that?
Another thing need to highlight. I have Google Tag manager implemented. Does this crash with ecommerce plugin ?
I had to set everywhere newTracker
ga('create', 'UA-77806616-1', 'auto',{'name': 'newTracker'});
ga('newTracker.require', 'ec');
ga('newTracker.ec:addPromo', {
'id': 'xyz1', // Promotion ID - Required Type: string
'name': 'name2', // Promotion Name - Type: string
'creative':'', // Creative ad used for promotion - Type: string
'position':'' // Position of the creative ad - Type: string
});
Related
When I compare transactions in my production database with transactions in the Google Analytics Ecommerce dashboard, it is evident that I am missing a significant amount of data. I made a purchase for testing purposes in my website and in the "Thank you page" that appears after a successful purchase, I saw the following Google Analytics tracking code when I inspected the element:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '[My Google Analytics tracking ID]', 'auto');
ga('require', 'ec');
ga('ec:addProduct', {
'id': '[Product ID]', 'name': '[Product name]', 'category': '[Product category]',
'brand': '[Product brand]', 'variant': '[Product variant]', 'price': '[Product price]', 'quantity': 1 });
// Transaction level information is provided via an actionFieldObject.
ga('ec:setAction', 'purchase', { 'id': '[Transaction ID]', 'affiliation': '[Organization where the transaction took place]', 'revenue': '[Revenue value]' });
ga('send', 'pageview');
</script>
This transaction took place about 24 hours ago. When I go to the Google Analytics Ecommerce dashboard, to the "Sales Performance" section, when I look for a transaction with the ID that I sent in 'id': '[Transaction ID]' above, I cannot find that transaction:
In the oval above I am providing the [Transaction ID] but it is not found as you can see. I have found many cases in my database where there are transactions that I cannot find in Google Analytics Ecommerce.
Google Analytics is showing some transactions but not all of them. I examined the code sent to Google Analytics and it is correct, no syntax errors, everything is perfect. Why is the Google Analytics Ecommerce "Sales Performance" section missing transactions? Thank you.
UPDATE 1:
For 'name': '[Product name]', I am sending as the [Product name] a string of 145 B. To give you an idea, it would be approximately this long:
¡Lore T99 mi psumi ss E325 impl Dummyte Xtífthe + Printingand
Typesetting (Iñd Ustrylore, Ips um Hasbee, Nthein) Dustr Ss Ttandar!
(2018-01-05)
The text contains the following special characters:
¡
í
+
(
ñ
,
)
!
-
Is the length the problem (145 B), or the fact that I am sending special characters in the [Product name]?
The problem was that I was taking [Product category] from a database, and to my surprise many of those values had an empty line after the string. That was causing the Google Analytics code to look like this:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '[My Google Analytics tracking ID]', 'auto');
ga('require', 'ec');
ga('ec:addProduct', {
'id': '[Product ID]', 'name': '[Product name]', 'category': '[Product category]
',
'brand': '[Product brand]', 'variant': '[Product variant]', 'price': '[Product price]', 'quantity': 1 });
// Transaction level information is provided via an actionFieldObject.
ga('ec:setAction', 'purchase', { 'id': '[Transaction ID]', 'affiliation': '[Organization where the transaction took place]', 'revenue': '[Revenue value]' });
ga('send', 'pageview');
</script>
Notice how [Product category] does not appear in a single line. That was the cause of the problem. Surely that was interpreted as a JavaScript syntax error and Google Analytics never processed that entry, which would be a synonym of not running the Google Analytics script. The fix was to remove those unnecessary lines from my database. Alternatively, if you are using PHP for instance, you could use the PHP trim function ("Strip whitespace (or other characters) from the beginning and end of a string": http://php.net/manual/en/function.trim.php) so that your PHP code takes care of fixing those extra lines at the end of the category names. But I think the best approach would be to fix the category names in your database because otherwise a similar situation could potentially cause similar errors in other APIs or scripts that you have today or write in the future. If your code is not written in PHP, find an equivalent to the trim function in the programming language that you use.
What I'd like to do is change the names of certain fields for better tracking for my website. I don't have a tax, and organization doesn't ship anything. So I was wondering if I could change those fields to something else like shipping -> gifts, and track for any additional funds donated part of their initial donation, that would be awesome. I've tried googling this but there's so much information to sort through that so far I haven't found an answer.
Google's provided code
ga('create', 'UA-XXXXX-Y');
ga('require', 'ec');
ga('set', '&cu', 'EUR'); // Set tracker currency to Euros
ga('ec:setAction', 'purchase', {
id: 'T12345',
affiliation: 'Google Store - Online',
revenue: '28.03',
tax: '2.14',
shipping: '4.00',
});
ga('send', 'pageview');
The code I'd like to use
<script>
var formatDollar = '[[S120:dc:giftAmount]]';
formatDollar.split(",").join("");
var dollarAmt = formatDollar.split(",").join("");
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y');
ga('require', 'ec');
ga('ec:setAction', 'purchase', {
id: '[[S120:dc:transactionID]]',
affiliation: '[[S120:dc:donationFormName]]',
revenue: dollarAmt,
category: '[[S120:dc:giftType]]',
currency: 'CAD'
gifts: '[[S120:dc:additionalGifts]]',
});
ga('ecommerce:send');
ga('send', 'pageview');
Would this work? (I know my UA code needs to be fixed I just forgot what the code was so i just put whatever).
I would test it, but right now the person in charge of all the GA stuff just left for the week, so I won't know if it works or not until they come back (no access to the GA account).
Thank you for your time.
You could change the name, but GA won't recognise those names and know what to do with them. If some parameters don't apply, like shipping, then you could simply leave them out; only id is required. Or if you want to include other parameters, then they would need to be done as custom dimensions:
ga('ec:setAction', 'purchase', {
id: '[[S120:dc:transactionID]]',
affiliation: '[[S120:dc:donationFormName]]',
revenue: dollarAmt,
category: '[[S120:dc:giftType]]',
currency: 'CAD',
dimension1: '[[S120:dc:additionalGifts]]',
});
where dimension1 is configured as a product-scoped custom dimension and contains the value for your gifts.
i manage several hotels on analytics, actually have like 400, and we are updating the ecommerce data to enhanced ecommerce.
when i updated the scripts to e ecommerce on 100 hotels, no one was working, so i ran a test and i found that the isogram analytics code wasnt implemented, fixed that and now 70/100 hotels are getting ecommerce data.
idk if is matter of time to get the data on the last 30 hotels but here is the code, if anyone can see anything wrong, thanks.
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'viewcode', 'auto', {'allowLinker': true});
// Load the plugin.
ga('require', 'linker');
// Define which domains to autoLink.
ga('linker:autoLink',['websites']);
ga('send', 'pageview');
ga('require', 'ec');
ga('set', '&cu', 'MXN');
ga('ec:addProduct', {
'id': '{SkuCode}',
'name': '{ProductName}',
'category': '{Category}',
'price': '{UnitPrice}',
'quantity': {Quantity}
});
ga('ec:setAction', 'purchase', {
id: '{NoReservation}',
revenue: '{Total}',
tax: '{Tax}'
});
ga('send', 'event');
</script>
The analytics code that you are using it looks right, however in order to assure that analytics code is pushed from the all the hotels websites I recommend you to follow the following steps:
1) Check that hotels domains name are correctly in the "linker" parameter
2) Verify that those websites dont't have another GA analytics code that overwrite your code. In order to avoid conflicts I recommend you to rename the "ga" global object to "myga" or something like that. Example:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','myga');
myga('create', 'viewcode', 'auto', {'allowLinker': true});
// Load the plugin.
myga('require', 'linker');
// Define which domains to autoLink.
myga('linker:autoLink',['websites']);
myga('send', 'pageview');
...
You can check when a hotel is pushing events if you are using the GA Real-time in the GA dashboard.
I am trying to enable ecommerce tracking on a site.
The payment part takes part inside an iframe of a third party. Once complete the iframe refreshes to a page on the main site in the same domain as the main site.
Google aynalitics is initially set up when the top page first loads with
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '******', 'example.com');
ga('send', 'pageview');
This part is working fine. Page tracking is working.
Once the payment has completed the iframe loads this code:
window.parent.ga('require', 'ecommerce');
window.parent.ga('ecommerce:addTransaction', {
'id': '1234',
'affiliation': 'Example',
'revenue': '4.00',
'shipping': '1.25',
'currency': 'GBP'
});
window.parent.ga('ecommerce:addItem', {
'id': '1234',
'name': 'test product',
'sku': 'TEST-SKU',
'category': 'Test Category',
'price': '2.75',
'quantity': '1'
});
window.parent.ga('ecommerce:send');
I can see that network traffic is generated from this but nothing is showing up on the ecommerce analytics pages.
The ecommerce tracking options are set up on the analytics admin page
Turns out the data just hadn't come through yet and everything was working fine. I thought the 24 hour delay was just after you turn it on, but it seems there is always at least 12 hours between transactions being made and their showing up in analytics.
So I've got the correct ecommerce tracking code for the new Google Universal Analytics, but I'm confused about how the variables populate? How do I get the correct item, price, category or number of items (for addItem) into this script? I've been looking all over the web, I don't think I'm seeing the full picture here.
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-44464798-1', 'safeway.com');
ga('send', 'pageview');
ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {
'id': '200028184', // Transaction ID. Required.
'affiliation': 'Safeway', // Affiliation or store name.
'revenue': '11.99', // Grand Total.
'shipping': '5.00', // Shipping.
'tax': '1.00' // Tax.
});
ga('ecommerce:addItem', {
'id': '200028184', // Transaction ID. Required.
'name': 'Apples', // Product name. Required.
'sku': 'CVC2US', // SKU/code.
'category': '', // Category - you can put some category if we have such
'price': '11.99', // Unit price.
'quantity': '1' // Quantity.
});
// If there are additional items they should be added the same way. The sum of all Items prices should match with the "revenue" data from above.
ga('ecommerce:send'); //
</script>
I don't know what language your site is written in. Assuming its PHP or asp.net you will need to go in to the code that builds the site itself and add these tags as well.
So to answer your question, the variables and values are populated by you in the code behind of your site. Probably at the same time as when the user is checking out.
Instead of values in your script, you want to refer to the values of variables.
These would get assigned by the shopping cart code at the moment of purchase completion.
The Google documentation has a PHP example.
Analytics JS Ecommerce Dev Notes