问题描述
所以我在GTM数据层中设置了电子商务代码,但是在将其发送到Google Analytics(分析)后,我希望页面被重定向,所以我知道我应该使用eventCallback,但由于某些原因它无法正常工作.
So i have Ecommerce code setup in GTM data layer, but after that is sent to Analytics i want the page to be redirected so i know i should be using eventCallback but it is not working for some reason.
<body>
<script>
dataLayer = [{
'transactionId': '56833',
'transactionAffiliation': 'TestName',
'transactionTotal': 1540.00,
'transactionTax': 385,
'transactionShipping': 0,
'transactionProducts': [{
'sku': 'FFSS44HH',
'name': 'test',
'category': 'TestCategory',
'price': 1540.00,
'quantity': 2
}],
'eventCallback': function() {
document.location.href='https://www.paypal.com/something';
}
}];
</script>
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(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=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXX');</script>
<!-- End Google Tag Manager -->
我已在GTM中为此网址设置了电子商务触发规则.我尝试了hitCallback和eventCallback,但是重定向没有发生...我在这里做什么错了?
I have set up Ecommerce firing rule in GTM for this URL. I tried hitCallback and eventCallback but the redirect does not happen... What am i doing wrong here?
推荐答案
我认为我找到了一个解决方案,我只是在数据层的末尾添加了这个('event':'datalayerReady'):
i think i found a solution, i just added this ('event' : 'datalayerReady') at the end of the data layer:
'event' : 'datalayerReady',
'eventCallback': function() {
document.location = "https://www.paypal.com/something";
}
这篇关于GTM数据层eventCallback函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!