谷歌分析-自定义维度为JS变种

Google Analytics - Custom Dimension as JS var

本文关键字:JS 变种 自定义 谷歌      更新时间:2023-09-26

我已经搜索了这个答案,因为我确信它在那里,但我似乎找不到它。我有一个自定义维度,我正试图将其发送回谷歌分析。

维度应该是一个javascript var,但我认为我做的代码不对,因为我收到的只是var名称,而不是它所代表的数值。这是代码-我希望这是一个新手错误:

<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>

提前感谢!

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