1

upon our thank you page we have a our addTransaction and addItem code followed by the ga:send code.

We noticed that it is posting each and every single item to google analytics upon page load - which on thousand line orders is slowing down the thank you page.

I searched and searched - is there a batch request for adding items into analytics?

I want to post a single request to post addTransaction and additem

ga('ecommerce:addTransaction', {
    'id': '***',
    'revenue': '***',
    'currency': '***'
});
ga('ecommerce:addItem', {
    'id': '***',
    'name': '***',
    'sku': '***',
    'category': '***',
    'price': '***',
    'quantity': '1'
});

ga('ecommerce:addItem', {
    'id': '***',
    'name': '***',
    'sku': '***',
    'category': '***',
    'price': '***',
    'quantity': '1'
});

ga('ecommerce:addItem', {
    'id': '***',
    'name': '***',
    'sku': '***',
    'category': '***',
    'price': '***',
    'quantity': '1'
});
ga('ecommerce:send');
steve hype
  • 38
  • 6

1 Answers1

0

There should be a single request sent to Google Analytics, only when you send the transaction :

ga('send:ecommerce');

So I'm guessing that your loading time problems are coming from the on page processing more than the HTTP requests to GA.

You can wait for your thank you page to load before processing and sending the transactions so that it doesn't slow the UI generation for the user :

With JQuery (make sure it's the last $.ready() function on the page) :

$(document).ready(function() {
  // ...
  // Your Google Analytics functions here.
  // ...
});

Without JQuery, you can just make sure that the Google Analytics Ecommerce scripts are implemented as the last script of your website.

<head>
  <!-- Your scripts running on page load -->
</head>
<body>
  <!-- Your website content -->
  <script>
    (function() {
      // ...
      // Your Google Analytics Ecommerce functions.
      // ...
    })();
  </script>
</body>
Source used for the no-JQuery implementation style.

This should allow your page to load THEN process the GA scripts (without impacting your page loading time).

EDIT : According to comments, it looks like, in the end, this does not solve the one product = one request problem.

Community
  • 1
  • 1
TimmyCarbone
  • 405
  • 2
  • 10
  • unfortunately that does not work. still for each item, it sends a request to GA adding that item to transaction. So in the code above (including the doc ready) it sends 1 for transaction- in the url I can see t=transaction and one for each item t=item So 3 items in 1 transaction is 4 calls - any way around this? – steve hype Jul 17 '15 at 14:12
  • 1
    The thing about ga('ecommerce:send') is that internally it calls - ga('send', 'transaction', {...}) once for your transaction, then ga('send', 'item', {...}) once for each item there is: http://stackoverflow.com/questions/18812345/js-analytics-ecommerce-callback But I don't see a clean solution – steve hype Jul 17 '15 at 14:34
  • Wow, I didn't expect that. This is awful ... I don't know if it's an option for you but maybe (I'm really not sure) Google Tag Manager solves that problem ? http://www.simoahava.com/analytics/ecommerce-tips-google-tag-manager/ – TimmyCarbone Jul 22 '15 at 14:45