[英]Google Analytics (gtag.js): Product List Name doesn't appear but other fields do
[英]why the gtag event doesn't appear in Google Analytics?
我的腳本是這樣的:
<html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxx-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-xxxxxxxx-1');
console.log('test');
console.log(gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' }));
</script>
</head>
<body>
...
<a onclick="gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' });" class="test" href="...">
<div class="text">test</div>
</a>
...
</body>
</html>
console.log(gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' })); </script>
console.log(gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' })); </script>
undefined
單擊測試按鈕后,我嘗試檢查谷歌分析。 結果是這樣的:
總事件數 = 0
怎么會這樣? 代碼編寫過程是否錯誤?
gtag.js 事件跟蹤語法如下:
gtag('event', 'action', {'event_category': 'category', 'event_label': 'label', 'value': value});
參考:https://developers.google.com/analytics/devguides/collection/gtagjs/events
event_label 和 value 是可選的。
根據@Michele Pisani 評論 event_action 不是有效參數
以下應該適用於您的鏈接
<a onclick="gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_label':'Live365BroadcastLaunch-ListenLive' });" class="test" href="...">
有時,當鏈接在同一瀏覽器 window 中加載新頁面時,它發生在 GA 可以發送和跟蹤事件命中之前。 在這些情況下,將 target="_blank" 添加到鏈接會有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.