Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've tested pushing custom variables of exactly 64 characters combined, and it looks like 64 is ONLY the encoded bytes of the key and the value, not of any connecting characters. </p> <p>You should use <code>encodeURIComponent</code>, because than <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURI" rel="nofollow"><code>encodeURI</code> does not encode <code>&amp;</code>, <code>+</code>, and <code>=</code></a>.</p> <p>Also, don't forget the underscore in front of <code>_gaq</code>. <code>_gaq</code> <em>needs</em> to be a global variable, so, no need to pass it through as a parameter. </p> <p>It looks like your general approach works, and avoids the issue of mistakenly cropping the string in the middle of an encoded character (as my previous approach mistakenly did.)</p> <p>Here's a slimmed down version of your code (cuts ~220 chars):</p> <pre><code>function truncateCustomVarAndSet(index, name, value, scope) { while (value.length &amp;&amp; encodeURIComponent(name + value).length &gt; 64) { value = value.substring(0, value.length-1); } _gaq.push(['_setCustomVar', index, name, value, scope]); } </code></pre> <p>Tested with this:</p> <pre><code>truncateCustomVarAndSet(3,"34567890345678903=1=1=456789034567895678904567890","211222$#!#11221122112122112eeeqeqqeqefo1op2k1po12kop21pok2p1o",1) _gaq.push(["_trackPageview"]); </code></pre> <p>And that records as:</p> <blockquote> <p><strong>Custom Var 3</strong> <br> <strong>label</strong>: '34567890345678903=1=1=456789034567895678904567890' <br> <strong>value</strong>: '211222$' <br> <strong>scope</strong>: '1'</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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