Google Tag Manager Message Length Limit for Google Analytics

Google Analytics & Tag Manager

At LogicSpot, we’re always trying to set up Analytics with Enhanced Ecommerce support using Google Tag Manager (GTM) for our Magento clients. This is because we feel that, further along the line, it is much easier to maintain changes to existing tags as well as any new third party tags. In most cases we don’t even need to change the code.

However, sometimes we encounter problems caused by poor GTM documentation. A while ago we noticed that one of our Magento Client’s Product Lists was not tracking properly on Enhanced Ecommerce Analytics view, and the problem seemed to be inconsistent – some of the categories were not tracked while some worked perfectly.

We ‘re using a custom module to implement GTM, so once we had excluded our code as a possible cause of the problem we started debugging Analytics and its responses.

Google Analytics debugger

Using the Google Analytics Debugger plugin for Chrome we found out that for categories that aren’t working, we get an error. The message doesn’t tell us a lot, however one can assume that it has something to do with the length of message sent to Google Analytics… This could explain why some of the categories were being tracked, and some not.

We tested our assumption – by reducing the number of products within the problematic categories – and noticed that this was, indeed, a problem.

We searched through Google and Tag Manager Developer Documentation, however nothing indicated any length limit. So we posted a question on the Tag Manager product forum and, thanks to the help of a Google employee, it turns out there’s a 8k limit on hit sizes – and our biggest categories were sending over 11k of data!

Before we encountered this problem, we were using the standard Product impression tracking configuration as suggested in Google Developers . We then found out that it is actually possible to track long categories, we just needed to make a few adjustments. Instead of pushing the whole product impression list into dataLayer in JSON data, we could push the product impressions in batches. So if you also want to do it, all you need to do is to adjust your code to send multiple instances of dataLayer.push with a custom event (we’ve named it productImpressions). Once you’ve done that, you can then configure Tag Manager in a similar way.

Preview mode Tag Manager

After you’ve set this up, you can then test to see if your changes are working correctly (or not!) by enabling Debug mode in Tag Manager. Visiting large categories should result in multiple calls of productImpressions tag. As it runs out 24 hours later in Analytics our fix worked, and all categories for our client were tracked properly from this moment.

If you’re interested to learn more about our custom Google Tag Manager module for Magento, don’t hesitate to contact us!

 

  • Simo Ahava

    Hi,

    Just to sort out a bit of a misnomer in your article title, Google Tag Manager does not impose any hit limit on anything.

    The hit limit is in the Measurement Protocol, and it’s documented here:
    https://developers.google.com/analytics/devguides/collection/protocol/v1/reference#using-post

    GTM imposes no limitations by itself (except for a character limit in a Custom HTML Tag and some malware safeguards), as it’s 100% client-side JavaScript injector.

    When you send a hit with analytics.js, it first tries to use a GET request. If the character limit for GET of 2000 bytes (this is also documented in the link above) is reached, it automatically turns the request to POST, which has the 8192 byte restriction. If this is breached, then the hit will not get sent.

    There are many ways to keep the size of the payload down:
    – Only send impressions for products that are in the viewport
    – Only send product ID and use data import to add rest of dimensions
    – Chop up the impression requests to e.g. max. 30 products per request

    Simo

    • Kamil Szewczyk

      Hello Simo,
      thank you very much for this comment and clarification – especially for the link with Measurement protocol limitations. When we originally posted a thread on google groups we didn’t get response with any link, just a info that there is a hit limit size on requests and we built a workaround based on this answer