我之前在谷歌分析中跟踪点击以打开标签/模态等。我必须更改为新的gTag代码,现在没有跟踪js链接。我该如何解决这个问题?
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxx-5"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// line below previously pushed js links events
gtag('event', 'pageview', { 'page': location.pathname + location.search + location.hash});
gtag('config', 'UA-xxxxxxx-5', {
'linker': {
'domains': ['example.org.au']
}
});
答案 0 :(得分:1)
我修好了。
要获取包含页面加载时锚点的完整路径:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-xxxxxxx-5', {
'page_path': location.pathname + location.search + location.hash,
'linker': {
'domains': ['example.org.au']
}
});
</script>
然后跟踪JS中触发的事件(例如标签打开)
link = location.pathname.replace(/^[\/]/, '') + location.search + location.hash
gtag('event', 'page_view', {'page_path': link});