{"id":105253,"date":"2025-02-23T13:19:09","date_gmt":"2025-02-23T13:19:09","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/automatically-reduce-google-analytics-payload-length\/"},"modified":"2025-02-23T13:19:09","modified_gmt":"2025-02-23T13:19:09","slug":"automatically-reduce-google-analytics-payload-length","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=105253","title":{"rendered":"Automatically Reduce Google Analytics Payload Length"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p>Here we are, reunited with <a href=\"https:\/\/www.simoahava.com\/analytics\/customtask-the-guide\/\"><code>customTask<\/code><\/a>. This time, we\u2019ll put this wonderful mechanism to work for a very, very good cause. One of the lesser known \u201cfeatures\u201d of <a href=\"https:\/\/analytics.google.com\/\">Google Analytics<\/a> is that when the payload size (the request body that is actually sent to Google Analytics with each request) goes past a certain limit, specifically <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/protocol\/v1\/reference#using-post\">8192 bytes<\/a>, the hit is <strong>aborted<\/strong> without warning. This can come as a surprise, because there\u2019s no indication anywhere in Google Analytics that you are missing hits because of this.<\/p>\n<p>The solution? A nice little <code>customTask<\/code> script, which recursively whittles away parts of the payload until the length is just below the cap.<\/p>\n<div style=\"aspect-ratio: 908 \/ 225;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2018\/06\/automatically-reduce-payload-length.jpg\" title=\"Automatically reduce payload length\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"225\" width=\"908\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2018\/06\/automatically-reduce-payload-length.jpg#ZgotmplZ\" alt=\"Automatically reduce payload length\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>The idea is that you will be able to specify a list of payload parameters to be removed one by one from the payload until the size is safely below the maximum of 8192. First things that will go are some of the default dimensions that no one really uses, such as <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/protocol\/v1\/parameters#je\">\u2018Java Enabled\u2019<\/a> and <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/protocol\/v1\/parameters#de\">\u2018Document Encoding\u2019<\/a>. Next, you can list all the Custom Dimensions you want to get rid of, in order of priority.<\/p>\n<p>Finally, you\u2019ll be able to list the Enhanced Ecommerce impression parameters that you want to remove from each impression in the payload. The script will stop as soon as the length is below 8192, so you\u2019ll most likely end up with some impressions having more details than others.<\/p>\n<p>Why stop at impressions? Because, from experience, that\u2019s where most problems lie. It shouldn\u2019t be too difficult to customize the script to also include Promotions and even \u201cregular\u201d Enhanced Ecommerce product objects.<\/p>\n<p>Once you\u2019ve implemented this in your Enhanced Ecommerce tags, you should never see the following error in the console (if you have <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/google-analytics-debugger\/jnkmfdileelhofjcijamephohjechhna?hl=en\">Google Analytics Debugger<\/a> activated, or if you have Universal Analytics running in <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/debugging#the_debug_version_of_the_analyticsjs_library\">debug mode<\/a>):<\/p>\n<div style=\"aspect-ratio: 1101 \/ 47;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2018\/06\/warning.jpg\" title=\"payload length warning\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"47\" width=\"1101\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2018\/06\/warning.jpg#ZgotmplZ\" alt=\"payload length warning\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>I recommend implementing this <code>customTask<\/code> together with my solution for sending the <a href=\"https:\/\/www.simoahava.com\/analytics\/send-google-analytics-payload-length-as-custom-dimension\/\">payload length<\/a> as a custom dimension. This way you\u2019ll be able to detect if you\u2019re approaching the maximum length of the payload with your hits, and you can then proceed to implement this payload length limiter when necessary.<\/p>\n<p>For an alternative solution, take a look at <a href=\"https:\/\/www.bounteous.com\/insights\/2017\/02\/16\/tracking-large-transactions-w-google-analytics-google-tag-manager\/\">this excellent article<\/a> by the awesome Dan Wilkerson from the equally awesome <a href=\"https:\/\/www.bounteous.com\/\">Bounteous<\/a> blog.<\/p>\n<p>                <span class=\"simmer\"><br \/>\n  <span class=\"close\">X<\/span><\/p>\n<p>\n    <span class=\"fa fa-md fa-bell\"\/><br \/>\n    <strong>The Simmer Newsletter<\/strong>\n  <\/p>\n<p>\n    Subscribe to the <a href=\"https:\/\/www.simoahava.com\/newsletter\/\">Simmer newsletter<\/a> to get the latest news and content from Simo Ahava into your email inbox!\n  <\/p>\n<p>  <\/span><\/p>\n<h2 id=\"the-customtask-variable\">The <code>customTask<\/code> variable<\/h2>\n<p>To build the <code>customTask<\/code>, you need to create a new <strong>Custom JavaScript variable<\/strong>. Name it something like <strong>{{customTask &#8211; reduce payload length}}<\/strong>.<\/p>\n<blockquote>\n<p><strong>Note!<\/strong> If you already have a <code>customTask<\/code> implemented in your Enhanced Ecommerce tags, you\u2019ll need to combine the code below with the existing <code>customTask<\/code> script you already have. For tips on how to do this, consult <a href=\"https:\/\/www.simoahava.com\/analytics\/customtask-the-guide\/#putting-it-all-together-literally\">this guide<\/a>.<\/p>\n<\/blockquote>\n<p>Add the following code into the <code>customTask<\/code> variable body:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#00a\">function<\/span>() {\n  <span style=\"color:#00a\">return<\/span> <span style=\"color:#00a\">function<\/span>(customModel) {\n    <span style=\"color:#aaa;font-style:italic\">\/\/ Add any other default parameters you want to strip from the payload\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#aaa;font-style:italic\">\/\/ into this array in order of priority. \n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#aaa;font-style:italic\">\/\/ For more details, visit: https:\/\/bit.ly\/2MOhjBD\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#00a\">var<\/span> defaultParams = [<span style=\"color:#a50\">'&amp;je'<\/span>, <span style=\"color:#a50\">'&amp;de'<\/span>, <span style=\"color:#a50\">'&amp;sd'<\/span>, <span style=\"color:#a50\">'&amp;vp'<\/span>, <span style=\"color:#a50\">'&amp;sr'<\/span>];\n    \n    <span style=\"color:#aaa;font-style:italic\">\/\/ List the (regular) Custom Dimensions you want to strip from the\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#aaa;font-style:italic\">\/\/ payload in order of priority. Leave the array empty if you don't\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#aaa;font-style:italic\">\/\/ want to remove Custom Dimensions. \n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#aaa;font-style:italic\">\/\/ For more details, visit: https:\/\/bit.ly\/2MM6O1O\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#00a\">var<\/span> customDims = [<span style=\"color:#a50\">'&amp;cd198'<\/span>, <span style=\"color:#a50\">'&amp;cd199'<\/span>, <span style=\"color:#a50\">'&amp;cd200'<\/span>];\n\n    <span style=\"color:#aaa;font-style:italic\">\/\/ List the impression object parameters you want to strip from the\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#aaa;font-style:italic\">\/\/ payload in order of priority. Only list the field specifier, so\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#aaa;font-style:italic\">\/\/ instead of '&amp;il1pi2va', write 'va', and instead of '&amp;il1pi4cd3', write\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#aaa;font-style:italic\">\/\/ 'cd3'. For more details, visit: https:\/\/bit.ly\/2KehCHF\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#00a\">var<\/span> impressions = [<span style=\"color:#a50\">'va'<\/span>, <span style=\"color:#a50\">'br'<\/span>, <span style=\"color:#a50\">'ca'<\/span>, <span style=\"color:#a50\">'ps'<\/span>, <span style=\"color:#a50\">'nm'<\/span>];\n    \n    <span style=\"color:#aaa;font-style:italic\">\/\/ Don't touch the code below.\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>    <span style=\"color:#00a\">var<\/span> maxLength = <span style=\"color:#099\">8192<\/span>,\n        globalSendTaskName = <span style=\"color:#a50\">'_'<\/span> + customModel.get(<span style=\"color:#a50\">'trackingId'<\/span>) + <span style=\"color:#a50\">'_sendHitTask'<\/span>,\n        originalSendHitTask = <span style=\"color:#0aa\">window<\/span>[globalSendTaskName] = <span style=\"color:#0aa\">window<\/span>[globalSendTaskName] || customModel.get(<span style=\"color:#a50\">'sendHitTask'<\/span>);\n  \n    customModel.set(<span style=\"color:#a50\">'sendHitTask'<\/span>, <span style=\"color:#00a\">function<\/span>(sendModel) {\n    \n      <span style=\"color:#00a\">var<\/span> ga = <span style=\"color:#0aa\">window<\/span>[<span style=\"color:#0aa\">window<\/span>[<span style=\"color:#a50\">'GoogleAnalyticsObject'<\/span>]];\n    \n      <span style=\"color:#aaa;font-style:italic\">\/\/ Only log if in analytics debug mode.\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>      <span style=\"color:#00a\">var<\/span> log = <span style=\"color:#00a\">function<\/span>(msg) {\n        <span style=\"color:#00a\">if<\/span> (<span style=\"color:#a50\">'dump'<\/span> <span style=\"color:#00a\">in<\/span> ga) {\n          <span style=\"color:#0aa\">window<\/span>.console.log.apply(<span style=\"color:#0aa\">window<\/span>.console, [msg]);\n        }\n      };\n    \n      <span style=\"color:#00a\">var<\/span> hitPayload = sendModel.get(<span style=\"color:#a50\">'hitPayload'<\/span>);\n    \n      <span style=\"color:#00a\">var<\/span> removeKeys = <span style=\"color:#00a\">function<\/span>(hitPayload, keys) {\n        <span style=\"color:#00a\">var<\/span> key, regex;\n        <span style=\"color:#00a\">while<\/span>(hitPayload.length &gt;= maxLength &amp;&amp; keys.length) {\n          key = keys[<span style=\"color:#099\">0<\/span>];\n          log(<span style=\"color:#a50\">'--&gt; Removing '<\/span> + key);\n          regex = <span style=\"color:#00a\">new<\/span> <span style=\"color:#0aa\">RegExp<\/span>(key + <span style=\"color:#a50\">'=[^&amp;]+'<\/span>, <span style=\"color:#a50\">'gi'<\/span>);\n          keys.shift();\n          hitPayload = hitPayload.replace(regex, <span style=\"color:#a50\">''<\/span>);\n          log(<span style=\"color:#a50\">'--&gt; New length: '<\/span> + hitPayload.length);\n        }\n        <span style=\"color:#00a\">return<\/span> hitPayload;\n      };\n    \n      <span style=\"color:#00a\">var<\/span> removeImpressions = <span style=\"color:#00a\">function<\/span>(hitPayload, keys) {\n        <span style=\"color:#00a\">var<\/span> key, regex, oldKey;\n        <span style=\"color:#00a\">while<\/span>(hitPayload.length &gt;= maxLength &amp;&amp; keys.length) {\n          <span style=\"color:#00a\">if<\/span> (key !== keys[<span style=\"color:#099\">0<\/span>]) {\n            key = keys[<span style=\"color:#099\">0<\/span>];\n            log(<span style=\"color:#a50\">'--&gt; Removing &amp;ilNpiN'<\/span> + key + <span style=\"color:#a50\">' from impression objects'<\/span>);\n          }\n          regex = <span style=\"color:#00a\">new<\/span> <span style=\"color:#0aa\">RegExp<\/span>(<span style=\"color:#a50\">'&amp;il\\\\d+pi\\\\d+'<\/span> + key + <span style=\"color:#a50\">'=[^&amp;]+'<\/span>, <span style=\"color:#a50\">'i'<\/span>);\n          <span style=\"color:#00a\">if<\/span> (!regex.test(hitPayload)) {\n            keys.shift();\n          }\n          hitPayload = hitPayload.replace(regex, <span style=\"color:#a50\">''<\/span>);\n        }\n        log(<span style=\"color:#a50\">'--&gt; New length: '<\/span> + hitPayload.length);\n        <span style=\"color:#00a\">return<\/span> hitPayload;\n      };\n\n      <span style=\"color:#aaa;font-style:italic\">\/\/ If over payload length, remove default parameters.\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>      <span style=\"color:#00a\">if<\/span> (hitPayload.length &gt;= maxLength) {\n        log(<span style=\"color:#a50\">'Payload too long ('<\/span> + hitPayload.length + <span style=\"color:#a50\">'), removing default keys...'<\/span>);\n        hitPayload = removeKeys(hitPayload, defaultParams);\n      }\n      <span style=\"color:#aaa;font-style:italic\">\/\/ If over payload length, remove custom dimensions.\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>      <span style=\"color:#00a\">if<\/span> (hitPayload.length &gt;= maxLength) {\n        log(<span style=\"color:#a50\">'Payload still too long ('<\/span> + hitPayload.length + <span style=\"color:#a50\">'), removing Custom Dimensions...'<\/span>);\n        hitPayload = removeKeys(hitPayload, customDims);\n      }\n      <span style=\"color:#aaa;font-style:italic\">\/\/ If over payload length, clean up impression objects.\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>      <span style=\"color:#00a\">if<\/span> (hitPayload.length &gt;= maxLength) {\n        log(<span style=\"color:#a50\">'Payload still too long ('<\/span> + hitPayload.length + <span style=\"color:#a50\">'), cleaning up Impressions...'<\/span>);\n        hitPayload = removeImpressions(hitPayload, impressions);\n      }\n    \n      <span style=\"color:#aaa;font-style:italic\">\/\/ Send the modified payload.\n<\/span><span style=\"color:#aaa;font-style:italic\"\/>      sendModel.set(<span style=\"color:#a50\">'hitPayload'<\/span>, hitPayload, <span style=\"color:#00a\">true<\/span>);\n      originalSendHitTask(sendModel);\n    });\n  };\n}\n<\/code><\/pre>\n<\/div>\n<p>Make sure you edit the <code>defaultParams<\/code>, <code>customDims<\/code>, and <code>impressions<\/code> arrays to include the keys you want to purge from the <code>dataLayer<\/code>. Note that you will need to list the keys using their <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/protocol\/v1\/parameters\">Measurement Protocol parameter names<\/a> rather than what their <strong>analytics.js<\/strong> field names are. So instead of <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#encoding\"><code>'encoding'<\/code><\/a>, for example, you need to use <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/protocol\/v1\/parameters#de\"><code>'&amp;de'<\/code><\/a>.<\/p>\n<p>The keys I have added to the <code>defaultParams<\/code> array are:<\/p>\n<table>\n<thead>\n<tr>\n<th>Key<\/th>\n<th>Name<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>&amp;je<\/code><\/td>\n<td>Java Enabled<\/td>\n<td>Whether the browser has enabled Java or not.<\/td>\n<\/tr>\n<tr>\n<td><code>&amp;de<\/code><\/td>\n<td>Document Encoding<\/td>\n<td>What the character encoding of the current page is (e.g. <code>UTF-8<\/code>).<\/td>\n<\/tr>\n<tr>\n<td><code>&amp;sd<\/code><\/td>\n<td>Screen Colors<\/td>\n<td>The screen color depth (e.g. <code>24-bits<\/code>).<\/td>\n<\/tr>\n<tr>\n<td><code>&amp;vp<\/code><\/td>\n<td>Viewport Size<\/td>\n<td>The viewable area (in pixels) of the browser or device.<\/td>\n<\/tr>\n<tr>\n<td><code>&amp;sr<\/code><\/td>\n<td>Screen Resolution<\/td>\n<td>The screen resolution (in pixels) of the browser or device.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Naturally, you might want to preserve some of these, e.g. <code>&amp;vp<\/code> or <code>&amp;sr<\/code>. Feel free to edit the <code>defaultParams<\/code> array as you see fit.<\/p>\n<p>When adding items to the <code>impressions<\/code> array, the syntax is slightly more complex. You should <strong>only<\/strong> add the actual parameter specifier, which is the key that comes after <code>&amp;ilNpiN<\/code>. So if the parameter name for Product Impression Variant is <code>&amp;il2pi1va<\/code>, you\u2019d type just <code>'va'<\/code> into the array. Or, if you wanted to purge the Product-Scoped Custom Dimension from index 3 from your impression objects, instead of typing <code>'&amp;il1pi1cd3'<\/code>, you\u2019d type <code>'cd3<\/code> into the array.<\/p>\n<p>Note that for <code>defaultParams<\/code> and <code>customDims<\/code> you need to type the full parameter name <strong>with<\/strong> the leading <code>&amp;<\/code>.<\/p>\n<h2 id=\"add-the-variable-to-your-tag\">Add the variable to your tag<\/h2>\n<p>This variable should be added to the tag which sends the Enhanced Ecommerce payload with impression objects to Google Analytics. To add it to the tag, either edit the <a href=\"https:\/\/www.simoahava.com\/analytics\/google-analytics-settings-variable-in-gtm\/\">Google Analytics Settings variable<\/a> in the impression tag, or add the field directly to the tag.<\/p>\n<p>Browse to <strong>More Settings<\/strong> -&gt; <strong>Fields to set<\/strong>, and add the following field:<\/p>\n<p><strong>Field name<\/strong>: customTask<br \/><strong>Value<\/strong>: {{customTask &#8211; reduce payload length}}<\/p>\n<p>Like so:<\/p>\n<div style=\"aspect-ratio: 891 \/ 232;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2018\/06\/fields-to-set.jpg\" title=\"Fields to set\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"232\" width=\"891\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2018\/06\/fields-to-set.jpg#ZgotmplZ\" alt=\"Fields to set\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>And that\u2019s it for the setup! Now, if your payload is over 8192, the script will first chop out the parameters specified in the <code>defaultParams<\/code> array. Then it will gobble up the dimensions in the <code>customDims<\/code> array. Finally, if the payload is STILL too long, it will proceed to clean up your impressions objects by removing the fields listed in <code>impressions<\/code> one by one, impression by impression.<\/p>\n<h2 id=\"how-to-debug\">How to debug<\/h2>\n<p>If you walked through the code, as I\u2019m sure you did, you might have noticed how I use a custom method named <code>log()<\/code> to send some debug data to the console. The thing is, I don\u2019t want to pollute the JavaScript console with debug messages when Google Analytics is <strong>not<\/strong> in debug mode, so I do a simple check to see if the debug version of <strong>analytics.js<\/strong> is loaded:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-javascript\" data-lang=\"javascript\"><span style=\"color:#00a\">if<\/span> (<span style=\"color:#a50\">'dump'<\/span> <span style=\"color:#00a\">in<\/span> <span style=\"color:#0aa\">window<\/span>[<span style=\"color:#a50\">'ga'<\/span>]) {}\n<\/code><\/pre>\n<\/div>\n<p>Basically, if the global <code>ga<\/code> object has the method <code>dump<\/code>, I\u2019m assuming the user is using the debug version of <strong>analytics.js<\/strong>.<\/p>\n<blockquote>\n<p><strong>NOTE!<\/strong> If someone has figured a more robust way to check for the debug version of analytics.js, please let me know! Thank you.<\/p>\n<\/blockquote>\n<p>So, if you want to see debug messages, you can set the library to debug mode by browsing to <strong>More Settings<\/strong> -&gt; <strong>Advanced Configuration<\/strong> -&gt; <strong>Use Debug Version<\/strong> in your Google Analytics tag or Google Analytics Settings variable, and setting it to <code>true<\/code>. Or, you can use the <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/google-analytics-debugger\/jnkmfdileelhofjcijamephohjechhna?hl=en\">Google Analytics Debugger<\/a> browser extension.<\/p>\n<p>Once you have the debug library loaded, you can see debug messages such as these <strong>if<\/strong> the payload exceeds the maximum length of 8192:<\/p>\n<div style=\"aspect-ratio: 773 \/ 422;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2018\/06\/debug-messages.jpg\" title=\"Debug messages\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"422\" width=\"773\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2018\/06\/debug-messages.jpg#ZgotmplZ\" alt=\"Debug messages\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>In these debug messages you can see how the script walks through your payload, stripping out parameters where necessary.<\/p>\n<h2 id=\"summary\">Summary<\/h2>\n<p>I wish <strong>analytics.js<\/strong> had a more elegant way of handling payloads that are too large. Just dropping them is slightly overkill, in my opinion. analytics.js could, for example, compile a custom hit to GA when the payload maximum size is breached, and this would turn into a warning or notification in the Google Analytics UI. This way you\u2019d at least have a clue that something is amiss.<\/p>\n<p>So the <code>customTask<\/code> solution presented here is, as is typical for scripts that I write, a bandaid for something that will hopefully be remedied natively by the library itself in the future.<\/p>\n<p>Naturally, the \u201cbest\u201d way to avoid payloads that are too large is to only send relevant data to Google Analytics. In the case of impressions, for example, it doesn\u2019t really make sense to send <strong>every single impression<\/strong> on the page in one hit. Rather, you\u2019d want to only send impressions that the user has actually <em>viewed<\/em>. Luckily, I might just have a guide coming up that will show you how to track viewed impressions only.<\/p>\n<p>Let me know in the comments if you find this useful or if you have suggestions for improving the method!<\/p>\n<\/p><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Here we are, reunited with customTask. This time, we\u2019ll put this wonderful mechanism to work for a very, very good cause. One of the lesser known \u201cfeatures\u201d of Google Analytics is that when the payload size (the request body that is actually sent to Google Analytics with each request) goes past a certain limit, specifically [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":105255,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[12765,19133,1531,400,48221,9271],"dealstore":[],"offerexpiration":[],"class_list":["post-105253","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-analytics","tag-automatically","tag-google","tag-length","tag-payload","tag-reduce"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Automatically Reduce Google Analytics Payload Length - Som2ny Network<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fivemor.com\/?p=105253\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automatically Reduce Google Analytics Payload Length - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"Here we are, reunited with customTask. This time, we\u2019ll put this wonderful mechanism to work for a very, very good cause. One of the lesser known \u201cfeatures\u201d of Google Analytics is that when the payload size (the request body that is actually sent to Google Analytics with each request) goes past a certain limit, specifically [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=105253\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-23T13:19:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/automatically-reduce-payload-length.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"908\" \/>\n\t<meta property=\"og:image:height\" content=\"225\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=105253#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=105253\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"Automatically Reduce Google Analytics Payload Length\",\"datePublished\":\"2025-02-23T13:19:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=105253\"},\"wordCount\":1250,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=105253#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/automatically-reduce-payload-length.jpg\",\"keywords\":[\"Analytics\",\"automatically\",\"Google\",\"Length\",\"Payload\",\"Reduce\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=105253#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=105253\",\"url\":\"https:\/\/fivemor.com\/?p=105253\",\"name\":\"Automatically Reduce Google Analytics Payload Length - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=105253#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=105253#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/automatically-reduce-payload-length.jpg\",\"datePublished\":\"2025-02-23T13:19:09+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=105253#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=105253\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=105253#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/automatically-reduce-payload-length.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/automatically-reduce-payload-length.jpg\",\"width\":908,\"height\":225},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=105253#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automatically Reduce Google Analytics Payload Length\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fivemor.com\/#website\",\"url\":\"https:\/\/fivemor.com\/\",\"name\":\"Som2ny Network\",\"description\":\"Daily Deals\",\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fivemor.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/fivemor.com\/#organization\",\"name\":\"Som2ny Network\",\"url\":\"https:\/\/fivemor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"width\":300,\"height\":86,\"caption\":\"Som2ny Network\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/fivemor.com\"],\"url\":\"https:\/\/fivemor.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Automatically Reduce Google Analytics Payload Length - Som2ny Network","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fivemor.com\/?p=105253","og_locale":"en_US","og_type":"article","og_title":"Automatically Reduce Google Analytics Payload Length - Som2ny Network","og_description":"Here we are, reunited with customTask. This time, we\u2019ll put this wonderful mechanism to work for a very, very good cause. One of the lesser known \u201cfeatures\u201d of Google Analytics is that when the payload size (the request body that is actually sent to Google Analytics with each request) goes past a certain limit, specifically [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=105253","og_site_name":"Som2ny Network","article_published_time":"2025-02-23T13:19:09+00:00","og_image":[{"width":908,"height":225,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/automatically-reduce-payload-length.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=105253#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=105253"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"Automatically Reduce Google Analytics Payload Length","datePublished":"2025-02-23T13:19:09+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=105253"},"wordCount":1250,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=105253#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/automatically-reduce-payload-length.jpg","keywords":["Analytics","automatically","Google","Length","Payload","Reduce"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=105253#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=105253","url":"https:\/\/fivemor.com\/?p=105253","name":"Automatically Reduce Google Analytics Payload Length - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=105253#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=105253#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/automatically-reduce-payload-length.jpg","datePublished":"2025-02-23T13:19:09+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=105253#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=105253"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=105253#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/automatically-reduce-payload-length.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/02\/automatically-reduce-payload-length.jpg","width":908,"height":225},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=105253#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"Automatically Reduce Google Analytics Payload Length"}]},{"@type":"WebSite","@id":"https:\/\/fivemor.com\/#website","url":"https:\/\/fivemor.com\/","name":"Som2ny Network","description":"Daily Deals","publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fivemor.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fivemor.com\/#organization","name":"Som2ny Network","url":"https:\/\/fivemor.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","width":300,"height":86,"caption":"Som2ny Network"},"image":{"@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","caption":"admin"},"sameAs":["https:\/\/fivemor.com"],"url":"https:\/\/fivemor.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/105253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=105253"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/105253\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/105255"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=105253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=105253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=105253"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=105253"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=105253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}