http://code.google.com/apis/analytics/docs/履带/gaTrackingCustomVariables.html#varTypes”rel=“nofollow” 页: 1
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.
I have two questions about that:
- Should an encoded equal sign (=) be included in those 64 bytes?
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.)
function truncateCustomVarAndSet(index, name, value, scope) { var keyValuePair, encodedPair, lengthOK = false; while (!lengthOK && value.length > 0) { keyValuePair = name + = + value; encodedPair = encodeURIComponent(keyValuePair); lengthOK = encodedPair.length <= 64; if (!lengthOK) { value = value.substring(0, value.length - 1); } } _gaq.push([ _setCustomVar , index, name, value, scope]); }
<><>Edit>: 现在使用的是encodeURIComponent
,而不是encodeURI
。
<Edit2:@yahelc change gaq to _qac, 因此,我从论点清单中删除了“gaq”一词,因为现在更不需要。