Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make sure Google Analytics customVars are not too long
    text
    copied!<p>According to <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html#varTypes" rel="nofollow">Google Analytics</a>:</p> <blockquote> <p>The total combined length of any custom variable name and value may not exceed 64 bytes. Keep in mind that this is not equivalent to 64 characters. Because names and values are URI encoded when stored, some characters use more than one byte. For example, = is stored as %3D rather than = and uses 3 bytes rather than 1. To get a list of URI encoded values, search the web for URL encoding reference.</p> </blockquote> <p>I have two questions about that:</p> <ol> <li>Should an encoded equal sign (=) be included in those 64 bytes?</li> <li><p>I've tried to make a function that makes sure the custom name and value is not too long. Can it be improved? (Of course it can.)</p> <pre><code>function truncateCustomVarAndSet(index, name, value, scope) { var keyValuePair, encodedPair, lengthOK = false; while (!lengthOK &amp;&amp; value.length &gt; 0) { keyValuePair = name + '=' + value; encodedPair = encodeURIComponent(keyValuePair); lengthOK = encodedPair.length &lt;= 64; if (!lengthOK) { value = value.substring(0, value.length - 1); } } _gaq.push(['_setCustomVar', index, name, value, scope]); } </code></pre></li> </ol> <p><strong>Edit:</strong> Now using <code>encodeURIComponent</code> instead of <code>encodeURI</code>.</p> <p><strong>Edit 2:</strong> @yahelc changed gaq to _qac, so I removed gaq from the argument list since it isn't needed anymore.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload