我試圖在AMP標記中將內容分組變量分配給我的Google Analytics代碼。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>
我經常谷歌分析代碼:
<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項目谷歌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-分析支持變量的文檔: https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/analytics-vars.md
這裏是放大分析代碼的文檔:https://developers.google.com/analytics/devguides/collection/amp-analytics/
您的方法實際上可以通過其他更改實現,但「extraUrlParams」解決方案更加優雅。 –