[英]How do you implement google Analytics to tack a link click
我正在嘗試設置Google Analytics(分析)以跟蹤有人單擊鏈接的時間。 這是我到目前為止的內容:
這是在HEAD
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments) };
gtag('js', new Date());
gtag('config', 'UA-CODEHERE-2');
</script>
然后在我的HTML中有這個嗎?
<a target="_blank" onclick="_gaq.push(['_trackEvent', 'Click', 'CV Pack Download', 'CV Zip Downloads'])" href="path/file.pdf">Download now</a>
當我點擊鏈接時
_gaq is undefined
我想念什么?
您使用的是基於經典GA庫ga.js的較舊語法,該語法已被棄用。 可以在https://developers.google.com/analytics/devguides/collection/gtagjs/events上找到新語法。 您應該具有以下內容:
... onclick="gtag('event', 'CV Pack Download', {'event_category': 'Click', 'event_label': 'CV Zip Downloads'});" ...
簽名是:
gtag('event', 'event_name', { 'event_category': categoryName, 'event_label': labelName });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.