gpt4 book ai didi

google-analytics - AMP项目-Google Analytics(分析)-内容分组amp分析代码

转载 作者:行者123 更新时间:2023-12-03 15:48:10 25 4
gpt4 key购买 nike

我正在尝试在AMP标记中将内容分组变量分配给我的Google Analytics(分析)代码。

我的AMP分析代码:

<amp-analytics type="googleanalytics" id="analyticsgoogle1">
<script type="application/json">
{
"vars": {
"account": "UA-XXXXXXXX-X"
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview"
}
}
}
</script>
</amp-analytics>


我的常规Google Analytics(分析)代码:

<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-XXXXXXXX-X', 'auto');
ga('set', 'contentGroup1', 'My Category');
ga('set', 'contentGroup2', 'My Author Type');
ga('set', 'contentGroup3', 'My Author Name');
ga('send', 'pageview');
</script>


我知道它没有在文档中列出,但是我正在寻找类似的方法来使我的AMP页面可以像常规页面一样被跟踪。

可能带有内容分组的AMP Project Google Analytics(分析)代码:

<amp-analytics type="googleanalytics" id="analyticsgoogle1">
<script type="application/json">
{
"vars": {
"account": "UA-XXXXXXXX-X"
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview"
"vars": {
"contentGroup1": "My Category",
"contentGroup2": "My Author Type",
"contentGroup3": "My Author Name"
}
}
}
}
</script></amp-analytics>


在查看amp-analytics支持的变量的文档时,我看不到内容分组变量:
https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/analytics-vars.md

这是有关amp-analytics代码的文档: https://developers.google.com/analytics/devguides/collection/amp-analytics/

最佳答案

我提出了一个可行的解决方案。其实很简单。以下代码的注释相同。


cg1 = contentGroup1,cg2 = contentGroup2


关于Measurement protocol的详细信息

重要说明:如果要查看对GA的实际请求,请在浏览器中使用限制。在其他情况下,您会看到来自GA的重定向链,而不是您的实际请求。很烦人。

<amp-analytics type="googleanalytics" id="ga1">
<script type="application/json">
{
"extraUrlParams" : {
"cd4": "AMP"
<?php if($this->tracking_group_config['group'] === 'contentGroup1'):?>
,"cg1": "<?=$this->tracking_group_config['type']?>"
<?php elseif($this->tracking_group_config['group'] === 'contentGroup2'): ?>
,"cg2": "<?=$this->tracking_group_config['type']?>"
<?php endif; ?>
},
"vars": {
"account": "[Your GA account ID here]"
},
"triggers": {
"pageviewCustom": {
"on": "visible",
"request": "pageview"
}
}
}
</script>
</amp-analytics>

关于google-analytics - AMP项目-Google Analytics(分析)-内容分组amp分析代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40220904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com