我使用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交易代码。这样,只有在数据层准备就绪时,它才会被触发。

10-06 07:58