gpt4 book ai didi

javascript - 带有 localStorage 和 Google Analytics Ecommerce 的数据层

转载 作者:行者123 更新时间:2023-11-30 12:21:12 28 4
gpt4 key购买 nike

我使用 localStorage 创建了以下数据层。我们希望通过这种方式来避免额外的开发成本。

  <script>
dataLayer = [{
'transactionId': localStorage.getItem("t_transactionID"),
'transactionAffiliation': localStorage.getItem("t_storename"),
'transactionTotal': localStorage.getItem("t_total"),
'transactionTax': localStorage.getItem("t_tax"),
'transactionShipping': localStorage.getItem("t_shipping"),
'transactionProducts': [{
'sku': localStorage.getItem("i_transactionID"),
'name': localStorage.getItem("i_productname"),
'category': localStorage.getItem("i_category"),
'price': localStorage.getItem("i_unitprice"),
'quantity': localStorage.getItem("i_quantity")
}]
}];
</script>

我确定数据层已正确填充,因为当我使用 tagassistent 时,我看到:

  Parsed Data Layer
transactionId localStorage.getItem("t_transactionID")
transactionAffiliation localStorage.getItem("t_storename")
transactionTotal localStorage.getItem("t_total")
transactionTax localStorage.getItem("t_tax")
transactionShipping localStorage.getItem("t_shipping")
transactionProducts [{sku:localStorage.getItem("i_transactionID"),name:localStorage.getItem("i_productname"),category:localStorage.getItem("i_category"),price:localStorage.getItem("i_unitprice"),quantity:localStorage.getItem("i_quantity")}]
dataLayer
[
{
"transactionId": "107411435054374890",
"transactionAffiliation": "SYNTRA Limburg",
"transactionTotal": "195",
"transactionTax": "33.842975206611555",
"transactionShipping": "0",
"transactionProducts": [
{
"sku": "107411435054374890",
"name": "Summer School: Verkopen is fun (basis)",
"category": "Marketing en sales",
"price": "195",
"quantity": "1"
}
]
}

当我查看 Google Analytics 调试扩展时,我发现变量都未定义??

  Initializing Google Analytics.
analytics_debug.js:9 Loading resource for plugin: ecommerce
analytics_debug.js:9 Loading script: "http://www.google-analytics.com/plugins/ua/ecommerce.js"
analytics_debug.js:9 Running command: ga("create", "", {name: "gtm1435054433247", allowLinker: false})
analytics_debug.js:9 Creating new tracker: gtm1435054433247
analytics_debug.js:9 Running command: ga("gtm1435054433247.set", "&gtm", "GTM-N3HVZR")
analytics_debug.js:9 Running command: ga("gtm1435054433247.set", "hitCallback", [function])
analytics_debug.js:9 Running command: ga("gtm1435054433247.require", "displayfeatures", undefined, {cookieName: "_dc_gtm_"})
analytics_debug.js:9 Set called on unknown field: "dcLoaded".
analytics_debug.js:9 Plugin "displayfeatures" intialized on tracker "gtm1435054433247".
analytics_debug.js:9 Running command: ga("gtm1435054433247.send", "pageview")
analytics_debug.js:9
Sent beacon:
v=1&_v=j37d&a=1857107051&t=pageview&_s=1&dl=http%3A%2F%2Fwww.syntra-limburg.be%2Finschrijving%2Fsuccess%2F10398%2F1435054431.79&ul=n…id=&cid=1222114262.1433509428&tid=-1&gtm=GTM-N3HVZR&z=138757632


analytics_debug.js:9 <unknown> (&gtm)
analytics_debug.js:9 _j1 (&jid)
analytics_debug.js:9 adSenseId (&a) 1857107051
analytics_debug.js:9 apiVersion (&v) 1
analytics_debug.js:9 clientId (&cid) 1222114262.1433509428
analytics_debug.js:9 encoding (&de) UTF-8
analytics_debug.js:9 flashVersion (&fl) 18.0 r0
analytics_debug.js:9 hitType (&t) pageview
analytics_debug.js:9 javaEnabled (&je) 1
analytics_debug.js:9 language (&ul) nl
analytics_debug.js:9 location (&dl) http://www.syntra-limburg.be/inschrijving/success/10398/1435054431.79
analytics_debug.js:9 screenColors (&sd) 24-bit
analytics_debug.js:9 screenResolution (&sr) 1920x1080
analytics_debug.js:9 title (&dt) Inschrijven | SYNTRA Limburg | Uw opleiding, onze zaak
analytics_debug.js:9 trackingId (&tid)
analytics_debug.js:9 viewportSize (&vp) 1252x927
analytics_debug.js:9 Running command: ga("create", "", {name: "gtm1435054433249"})
analytics_debug.js:9 Running command: ga("gtm1435054433249.set", "&gtm", "GTM-N3HVZR")
analytics_debug.js:9 Running command: ga("gtm1435054433249.set", "hitCallback", [function])
analytics_debug.js:9 Running command: ga("gtm1435054433249.require", "ecommerce", "//www.google-analytics.com/plugins/ua/ecommerce.js")
analytics_debug.js:9 Waiting on require of "ecommerce" to be fulfilled.
analytics_debug.js:9 Executing Google Analytics commands.
analytics_debug.js:9 Registered new plugin: ga(provide, "ecommerce", Function)
analytics_debug.js:9 Running command: ga("gtm1435054433249.require", "ecommerce", "//www.google-analytics.com/plugins/ua/ecommerce.js")
analytics_debug.js:9 Plugin "ecommerce" intialized on tracker "gtm1435054433249".
analytics_debug.js:9 Running command: **ga("gtm1435054433249.ecommerce:addTransaction", {id: undefined, affiliation: undefined, revenue: undefined, shipping: undefined, tax: undefined})
analytics_debug.js:9 Running command:** ga("gtm1435054433249.ecommerce:send")

这是怎么回事?

数据层和一般 Google Analytics(分析)代码在“1 次网页浏览”时触发。在 2. DOM Ready 上,我触发了 Analytics 电子商务跟踪标签(来自 tagmanager 的交易标签)。

https://www.youtube.com/watch?v=ZKjlIhFJMCU我使用上面的视频作为设置标签和触发器的指南。我不会基于事件触发,而是基于 url(如果它包含成功一词)。

有人可以帮我解决这个问题吗?我认为这与首先触发哪个标签有关,但这似乎是正确的,所以很奇怪。

我从上面删除了我的 UA 和 tagmanager 代码。

最佳答案

我通过推送到我的数据层而不是仅仅定义它来修复它。

<script>

dataLayer.push({
'transactionId' : localStorage.getItem("t_transactionID"),
'transactionAffiliation' : localStorage.getItem("t_storename"),
'transactionTotal' : localStorage.getItem("t_total"),
'transactionTax' : localStorage.getItem("t_tax"),
'transactionShipping' : localStorage.getItem("t_shipping"),
'transactionProducts' : [{
'sku' : localStorage.getItem("i_transactionID"),
'name' : localStorage.getItem("i_productname"),
'category' : localStorage.getItem("i_category"),
'price' : localStorage.getItem("i_unitprice"),
'quantity' : localStorage.getItem("i_quantity")
}],
'event' : 'doneWithDataLayerPush'
});

</script>

当数据层被推送时,我添加了事件 doneWithDataLayerPush,我用它来触发 GA 交易标签。这样它只有在数据层准备就绪时才会被触发。

关于javascript - 带有 localStorage 和 Google Analytics Ecommerce 的数据层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31000270/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com