0
我試圖將ID推送到Google Analytics,但沒有看到它通過。這裏是我的cshtml代碼:即使在推送數據層時,也無法在Google Analytics中看到事件
@{
string id = Guid.NewGuid().ToString();
}
<script>
console.log('about to declare the datalayer');
var id = '@id';
console.log('id:' + id);
dataLayer = [{
'event': 'getIdentifier',
'uniqueIdentifier': id
}];
console.log('about to push the datalayer');
var dataLayer = window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'getIdentifier',
'uniqueIdentifier': id
});
console.log('finished pushing the datalayer');
</script>
我聲明瞭Google Tag Manager的東西和上面的代碼。
當頁面導航到時,我可以看到Id已創建並且所有console.log都已啓動,但沒有任何內容通過我的Google Analytics實時事件查看器進行。
我做錯了什麼?
谷歌標籤管理腳本在頭:
<!-- Google Tag Manager -->
<script>
console.log('about to do GTM2');
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','[container id]');
</script>
<!-- End Google Tag Manager -->
谷歌標籤管理腳本在身:
<!-- Google Tag Manager (noscript) -->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=[container id]"
height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<!-- End Google Tag Manager (noscript) -->
您只能初始化dataLayer ** BEFORE **頭部中的第一個腳本。如果你在放置代碼之前,你不能推動。 – Marco
GTM只是標籤管理器,所以沒有足夠的信息來期待GA中的任何事情。您在GTM事件中設置了哪些GA標籤,以及GTM調試器在此事件期間顯示的標籤及其內容? – lossleader
我實際上已經啓動了GTM Preview,現在我看到它了。我添加了標籤和自定義維度,我很好。 – crackedcornjimmy