简体   繁体   English

Google Analytics-自定义维度为JS变量

[英]Google Analytics - Custom Dimension as JS var

I have searched for this answer because I'm sure it's out there, but I can't seem to find it. 我已经搜索了此答案,因为我确定它在那里,但是我似乎找不到它。 What I have is a custom dimension that I'm trying to send back to google analytics. 我有一个自定义维度,我正尝试将其发送回Google Analytics(分析)。

The dimension should be a javascript var, but I don't think I'm doing the code right because all I get sent to GA is the var name and not the number value that it represents. 该维度应该是一个javascript var,但是我认为我做的代码不正确,因为我发送给GA的全部是var名称,而不是它代表的数字值。 Here's the code - I'm hoping it's a rookie mistake: 这是代码-我希望这是菜鸟的错误:

<script>
function myFunction()
{
var querystring = document.referrer.split('=')[2];
alert(querystring);
}
</script>
//this first part above serves to check that document.referrer.split is working
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-1', 'mydomain.com');//mydomain & UA-1 would be my domain & UA
ga('send', 'pageview');
ga('send', 'event', 'alertbutton', 'click', 'nav buttons');

var dimensionValue = 'UserEventsTest';
ga('set', 'dimension1', 'userid');

var userid = document.referrer.split('=')[2];

ga('send', 'pageview', {
'dimension1': 'userid'
});
</script>
//the above 'userid' is what I want to send, but as var userid
</head>

Thanks in advance! 提前致谢!

'dimension1': 'userid'更改为'dimension1': userid

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

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