Analytics
2.2K members online now
2.2K members online now
Learn how to set up goals and Ecommerce tracking, verify accuracy of attribution traffic sources, and discuss funnel visualization, Multi-Channel Funnels, the Goal Flow Report, and Enhanced Ecommerce
 
Guide Me
star_border
Reply

Google GA script only sending last item information

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi everyone,

 

We have implemented a the GA script on our thank you page however when there is more than 1 item in the list, only the last item actually gets sent to GA. Here is an example of the output that has been generated in the source of the webpage:

 

 

                ga('require', 'ecommerce');

                ga('ecommerce:addTransaction', {
                    'id': '34540',
                    'revenue': '490.0000',
                    'tax': '0.0000',
                    'currency': 'USD'
                });

                    
                        ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Alcoholic Drinks in India',
                            'category': 'Alcoholic Drinks',
                            'price': '98.0000',
                            'quantity': '1'
                        });
                    
                    
                        ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Alcoholic Drinks in New Zealand',
                            'category': 'Alcoholic Drinks',
                            'price': '98.0000',
                            'quantity': '1'
                        });
                    
                    
                        ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Alcoholic Drinks in Japan',
                            'category': 'Alcoholic Drinks',
                            'price': '98.0000',
                            'quantity': '1'
                        });
                    
                    
                        ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Alcoholic Drinks in Morocco',
                            'category': 'Alcoholic Drinks',
                            'price': '98.0000',
                            'quantity': '1'
                        });
                    
                    
                        ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Alcoholic Drinks in Georgia',
                            'category': 'Alcoholic Drinks',
                            'price': '98.0000',
                            'quantity': '1'
                        });
                    

                ga('ecommerce:send');

So, in the above code, there are many items but only the last item (Alcoholic Drinks in Georgia) will be sent to GA), which is giving inaccurate results as it shows only 1 item was sold with a transaction.

 

As far as I can see, this conforms to the code listed on this website: https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

 

Can anyone see any problems with the above code snippet, which would be causing this behaviour.

 

Thanks in advance.

 

 

 

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author emi l
November 2016

Re: Google GA script only sending last item information

Follower ✭ ✭ ✭
# 7
Follower ✭ ✭ ✭

hi @emi l

 

When you go here:  https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

 

in "Adding items" you have following:

 

ga('ecommerce:addItem', {
  'id': '1234',                     // Transaction ID. Required.
  'name': 'Fluffy Pink Bunnies',    // Product name. Required.
  'sku': 'DD23444',                 // SKU/code.
  'category': 'Party Toys',         // Category or variation.
  'price': '11.99',                 // Unit price.
  'quantity': '1'                   // Quantity.
});

 

whereas in yours:

   ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Alcoholic Drinks in Georgia',
                            'category': 'Alcoholic Drinks',
                            'price': '98.0000',
                            'quantity': '1'
                        });
                    

'id' - is a Transaction id 

'sku' - is where you should log your Product ID and it is missing in your implementation. So for each item purchased in the same transaction you need to have the same 'id' value (which is Transaction ID), but different 'sku'. 

 

Maybe worth giving a try. 

 

Seb

View solution in original post

Google GA script only sending last item information

Top Contributor
# 2
Top Contributor

You're always using the same product ID (34540). Make sure you use different product IDs otherwise GA will keep updating the same product.

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Google GA script only sending last item information

[ Edited ]
Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Hi

 

Thanks for your reply.

 

Are you sure the product ID's need to be different? As per the documentation on google analytics...it clearly states 'The transaction ID. This ID is what links items to the transactions to which they belong. (e.g. 1234)'. In the example given, 1234 is the same number used in the add transaction id section as well - indicating a link between transaction and items.


Thanks in advance!

Google GA script only sending last item information

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

Anyone got any other suggestions/comments/solutions?

Re: Google GA script only sending last item information

[ Edited ]
Follower ✭ ✭ ✭
# 5
Follower ✭ ✭ ✭

Hi, 

 

If it's the same product id and the same price, why not to reflect it in quantity, for example:

 

 ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Alcoholic Drinks in Georgia',
                            'category': 'Alcoholic Drinks',
                            'price': '98.0000',
                            'quantity': '5'

Might be easier than sending the same thing 5 times. Sorry if I get something wrong. 

 

Seb

Google GA script only sending last item information

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Its a different product...what I'm confused about is that the google documentation shows that the item id for each item should be the same id as the transaction id. But this is appearing up as only 1 item sold for each transaction, when there could be many.

Marked as Best Answer.
Solution
Accepted by topic author emi l
November 2016

Re: Google GA script only sending last item information

Follower ✭ ✭ ✭
# 7
Follower ✭ ✭ ✭

hi @emi l

 

When you go here:  https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

 

in "Adding items" you have following:

 

ga('ecommerce:addItem', {
  'id': '1234',                     // Transaction ID. Required.
  'name': 'Fluffy Pink Bunnies',    // Product name. Required.
  'sku': 'DD23444',                 // SKU/code.
  'category': 'Party Toys',         // Category or variation.
  'price': '11.99',                 // Unit price.
  'quantity': '1'                   // Quantity.
});

 

whereas in yours:

   ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Alcoholic Drinks in Georgia',
                            'category': 'Alcoholic Drinks',
                            'price': '98.0000',
                            'quantity': '1'
                        });
                    

'id' - is a Transaction id 

'sku' - is where you should log your Product ID and it is missing in your implementation. So for each item purchased in the same transaction you need to have the same 'id' value (which is Transaction ID), but different 'sku'. 

 

Maybe worth giving a try. 

 

Seb

Re: Google GA script only sending last item information

Follower ✭ ✭ ✭
# 8
Follower ✭ ✭ ✭

Hi @emi l

 

I've tried this one, checked it on a console and it worked fine. 

ga('require', 'ecommerce');

                ga('ecommerce:addTransaction', {
                    'id': '34540',
                    'revenue': '490.0000',
                    'tax': '0.0000',
                    'currency': 'USD'
                });

                    
                        ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Example name 1',
                            'sku':'1111',
                            'category': 'Exmample cat 1',
                            'price': '98.0000',
                            'quantity': '1'
                        });
                    
                    
                        ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Example name 2',
                            'sku':'2222',
                            'category': 'Exmample cat 2',
                            'price': '98.0000',
                            'quantity': '1'
                        });
                    
                    
                        ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Example name 3',
                            'sku':'3333',
                            'category': 'Exmample cat 3',
                            'price': '98.0000',
                            'quantity': '1'
                        });
                    
                    
                        ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Example name 4',
                            'sku':'4444',
                            'category': 'Exmample cat 4',
                            'price': '98.0000',
                            'quantity': '4'
                        });
                    
                    
                        ga('ecommerce:addItem', {
                            'id': '34540',
                            'name': 'Example name 5',
                            'sku':'5555',
                            'category': 'Exmample cat 5',
                            'price': '98.0000',
                            'quantity': '2'
                        });
                    

                ga('ecommerce:send');

it generated 6 ga hits (1 for transaction and 5 for item). All parameters such as 'ip' ,'iq', 'iv', 'ti' , 'tr', etc were fine. 

 

Also you may consider using enhanced e-commerce: https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce

 

Seb

 

Google GA script only sending last item information

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭

Thanks, this has solved my problem!

 

I saw in the console output that it sends all the 'Sent beacon' for each item rather than just the last item!

 

Thanks again!

Google GA script only sending last item information

Follower ✭ ✭ ✭
# 10
Follower ✭ ✭ ✭

i am happy it helped