Submit Google Analytics payload length as custom dimension – News Couple
ANALYTICS

Submit Google Analytics payload length as custom dimension


You probably know this, maybe you don’t, but requests sent from the website (or app) to Google Analytics have a maximum volume. Or more specifically, a file payload The size (meaning the body of the actual content of the request) has a max.

This maximum payload size is 8192 bytes. Basically, this means that the entire parameter string sent to the Google Analytics servers cannot be longer than 8192 characters. The thing is, if the payload exceeds this, Google Analytics simply drops the blow. No warning, no error, nothing. The hit just isn’t sent. If you are running a Google Analytics debugger browser extension, you can You already see a warning when the payload size is exceeded:

If you see this warning, it means that the entry was aborted due to exceeding 8192 payload length.

Note that if you use Measurement Protocol To send data directly to Google Analytics, this size limitation applies to POST request text. If you are sending data with a GET request, the max file size full / url collection He is 8000 bytes.

Anyway, in this article I will show you how to send the payload size (or at least a very close approximation to it) as a custom dimension to Google Analytics with each hit. This way you will be able to check if you are getting close to this limitation and thus you can take precautions to avoid exceeding the size limit. We’ll get things done customTask (What else?) and Google Tag Manager.

Update: Check out Angela Grammatas’ excellent article on the same topic. It uses a slightly different tactic, appending the data to a file buildHitTask, which also works.


X


Simmer . Newsletter

Subscribe to the Simmer newsletter to get the latest news and content from Simo Ahava right in your inbox!

Important request

Before I begin, I have a request to submit. Some time ago, someone called me (a Google employee, I think), and shared a similar solution with me. All my life, I can not find this connection anywhere, because I do not even remember the means by which I was contacted (I have passed through my mailbox to no avail).

This solution is definitely inspired by this person’s idea, so I want to give credit when it’s due. So, if you remember that you came close to a solution you used to work on and did something similar, please reach out to us and I will update this article with my thanks for your inspiring example.

Send the length of the access payload using customTask

If you don’t know what customTask Ho, please check out my guide on the subject. Something small, customTask Allows you to modify the request sent to Google Analytics, among other things before They are sent, dynamically adding the information to the payload. This information can be anything from a purged payload of personally identifiable information to a customer ID.

customTask Works with custom javascript variable. To send the length of the access payload as a custom dimension, you will first need to create a file hit the range A custom component in the Google Analytics admin. Once created, make a note of a file index assigned to the new dimension.

custom dimension

Then, in Google Tag Manager, create a file custom javascript variable. Call it something descriptive, for example customTask – Multiply the length of the payload. This is what you should add inside:

function() {
  // Change this index to match that of the Custom Dimension you created in GA
  var customDimensionIndex = 10;
  
  return function(model)  model.get('sendHitTask');
    
    model.set('sendHitTask', function(sendModel) 
      
      try 
        
        var originalHitPayload = sendModel.get('hitPayload');
        
        var hitPayload = sendModel.get('hitPayload');
        var customDimensionParameter = '&cd' + customDimensionIndex;
      
        // If hitPayload already has that Custom Dimension, note this in the console and do not overwrite the existing dimension
      
        if (hitPayload.indexOf(customDimensionParameter + '=') > -1) 
          
          console.log('Google Analytics error: tried to send hit payload length in an already assigned Custom Dimension');
          originalSendHitTask(sendModel);
        
         else 
      
        // Otherwise add the Custom Dimension to the string
        // together with the complete length of the payload
          hitPayload += customDimensionParameter + '=';
          hitPayload += (hitPayload.length + hitPayload.length.toString().length);
        
          sendModel.set('hitPayload', hitPayload, true);
          originalSendHitTask(sendModel);
        
        
       catch(e) 
       
        console.error('Error sending hit payload length to Google Analytics');
        sendModel.set('hitPayload', originalHitPayload, true);
        originalSendHitTask(sendModel);
        
      
    );
  ;
}

to configure this customTaskAll you have to do is update a file customDimensionIndex A variable with the index number of the custom dimension (in my example the index is 10).

This job is discontinued sendHitTask, which is the task used to actually submit the request to Google Analytics. The payload sent to Google Analytics is appended to the custom dimension you created, and the value of that custom dimension is set along the entire length of the payload. Thus, when the tag that uses this customTask Fires, the request to Google Analytics will contain the length of the payload as the value of the custom dimension you set for it.

To add it to your tag(s), use either the Google Analytics settings variable or override any tag’s settings. Scroll down to More settings > Fields to be set, and add a new field.

field name: customTask
Values: customTask – multiply the length of the payload

Fields to be set

Now, any tag containing this set of fields will add the length of the results payload as a custom dimension to the request.

You can check this by opening a file network Your browser’s developer tools tab. The tag is represented by a request to /collect, and by clicking on this order you can tell that the ‘custom component’ parameter is included in the payload length:

Payload length in network requests

Other ideas

You can already rewrite customTask To add more logic if you get close to 8192 Max size bytes. For example, it doesn’t really help to add the payload length as a custom dimension, if the payload is never sent because the size requirement is exceeded.

By adding some custom code, you can do things like:

  1. When the payload length is at 8192 bytes or more, drop the unnecessary fields from the payload until the length is less than the limit.

  2. When the payload is at 8192 bytes or more, submit a new result to Google Analytics which contains some basic information from the “broken” payload, just so you get an idea of ​​the scope of the problem.

The typical reason for overload length is if you are sending enhanced ecommerce impressions, or just very large shopping carts. It only takes 50-60 products to get close to the 8,192-byte limit. Unless you can reduce the product payload size using normal means you can do something like drop all non-critical fields from product objects (eg brandAnd categoryAnd variant), and just include a file idAnd nameAnd price, And quantity.

Or you can drop all product data except id In these cases, then use Data Import to update the additional data.

summary

Well, it looks like customTask to the rescue again. It’s a powerful feature, and I love the fact that you can have it all dead with your Google Analytics data.

Unloading the payload with otherwise obfuscated details is a great way to add a whole new level of correction opportunity to your dataset.

Payload size limitation is a bad thing because you won’t be alerted if a problem arises. The Google Analytics user interface will not be able to inform you of this issue because requests are never sent to GA in the first place. With this custom dimension, you can add this information to the payload as a custom dimension, then prepare in advance for the possibility that you will reach your maximum payload size sometime soon.



Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button