简体   繁体   English

Google Analytics(分析)设置了自定义维度值

[英]Google analytics set custom dimension value

Below, I've set my dimension1 value to dimensionValue . 在下面,我将我的dimension1值设置为dimensionValue This is a variable that I created above this snippet of code. 这是我在此代码段上方创建的变量。 The code above is a function that generates random number and letter and stores inside the variable dimensionValue , var dimensionValue = (formula for random string...) 上面的代码是一个函数,该函数生成随机数和字母,并将其存储在变量dimensionValuevar dimensionValue = (formula for random string...)

In my google analytics, the custom dimension was outputting dimensionValue for each user when I filtered for dimension1 in GA, whereas it should be outputting EE12345 etc. 在我的Google Analytics(分析)中,当我在GA中过滤dimension1时,自定义维度正在为每个用户输出dimensionValue值,而应该输出EE12345等。

On this line of code ga('set', 'dimension1', 'dimensionValue'); 在这行代码ga('set', 'dimension1', 'dimensionValue'); is dimensionValue written correctly with backticks around it, or should it contain no backticks 是DimensionValue正确书写,并带有反引号,还是应该不包含反引号

function getRChar() {
    return (Math.random() * 26 + 10 | 0).toString(36).toUpperCase();
    }

    var dimensionValue = getRChar() + getRChar() + Math.floor((Math.random() * 9999) * 7);

ga('create', 'UA-XXXXXX-Y', 'auto');
ga('set', 'dimension1', 'dimensionValue');
ga('send', 'pageview');

As Eike explained in the comments: 正如Eike在评论中解释的那样:

Drop the quotes. 删除引号。 As it stands dimensionValue is interpreted as a fixed string, not as a variable, so you always get the value of the string (which is of course always the same). 就目前而言,DimensionValue被解释为固定的字符串,而不是变量,因此您始终会获得字符串的值(当然,它总是相同的)。

Solution: 解:

ga('set', 'dimension1', dimensionValue);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM