GA Debug显示正在发送电子商务交易,但未显示数据

时间:2019-07-08 13:34:58

标签: javascript google-analytics e-commerce

我使用一个提供有限源代码控制的框架(Blackbaud Internet Solutions),试图将Google Analytics(分析)电子商务跟踪实施到我的网站中。

因为我使用的是自定义捐赠表格,所以[BB] BB文档中的此代码(https://www.blackbaud.com/files/support/guides/bbis/tkConfigureE-Commerce.html)无法正常工作,并且Google的大多数开发人员指南都假定源代码控制超出BBIS的允许范围。

这位于“管理”>“站点和设置”>“ [站点名称]”>“设置”选项卡下的““站点跟踪””部分(假定对于不熟悉BBIS的用户位于最前面)。

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXX-XX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-XXX-XX');
  gtag('require', 'ecommerce');
</script>

此代码显示在捐赠确认页面的底部:

<script type="text/javascript">
function returnDonationObject() {
      // First get the donation
      var gift = document.getElementById("givingSummary");
      var tds = gift.getElementsByTagName("td");
      var totalDonation = 0;

      for(var i = 0; i < tds.length; i++) {
        if(tds[i].innerText.indexOf("$") > -1) {
          var transformedNum = parseFloat(tds[i].innerText.slice(1, tds[i].innerText.length));
          totalDonation += transformedNum;
        }
      }
      totalDonation = totalDonation.toFixed(2);

      // Then get the GUID from the url
      var guid = window.location["href"].split("?t=")[1];

      // create and return the object
      var donationObject = {
        "transactionId" : guid,
        "transactionTotal" : totalDonation
      }
      return donationObject;
  }

  var donationObject = returnDonationObject();
  gtag('event', 'purchase', donationObject);
</script>

returnDonationObject返回预期的transactionId和transactionTotal,并使用GA Debug扩展程序,似乎成功触发了最终的gtag('event','purchase')函数:

Running command: ga("gtag_UA_XXX_XX.send", "event", {forceSSL: true, &gtm: "2ou6k2", hitCallback: [function], eventCategory: "ecommerce", eventAction: "purchase"})
Sent beacon:
v=1&_v=j77d&a=220349989&t=event&_s=3&dl=https%3A%2F%2Fsite-name.com%2Ffoundation%2Fdonate%2Fgive-online%3Ft%3Db2d87d89-e000-4457-8e43-xxxxxx&dr=https%3A%2F%2Fpayments.blackbaud.com%2FPages%2FSecurePayment.aspx%3Ft%3Db2d87d89-e000-4457-8e43-xxxxxxx&ul=en-us&de=UTF-8&dt=Foundation%20Donation%20Form&sd=24-bit&sr=1920x1080&vp=1313x937&je=0&ec=ecommerce&ea=purchase&_u=SCEAAUAL~&jid=&gjid=&cid=760857713.1560526567&tid=UA-XXX-XX&_gid=216294229.1562588238&gtm=2ou6k2&pa=purchase&z=1491483290

VM49 analytics_debug.js:16 <unknown>        (&gtm)  2ou6k2
VM49 analytics_debug.js:16 _j1              (&jid)  
VM49 analytics_debug.js:16 _j2              (&gjid) 
VM49 analytics_debug.js:16 adSenseId        (&a)    220349989
VM49 analytics_debug.js:16 apiVersion       (&v)    1
VM49 analytics_debug.js:16 clientId         (&cid)  760857713.1560526567
VM49 analytics_debug.js:16 ec:action        (&pa)   purchase
VM49 analytics_debug.js:16 encoding         (&de)   UTF-8
VM49 analytics_debug.js:16 eventAction      (&ea)   purchase
VM49 analytics_debug.js:16 eventCategory    (&ec)   ecommerce
VM49 analytics_debug.js:16 hitType          (&t)    event
VM49 analytics_debug.js:16 javaEnabled      (&je)   0
VM49 analytics_debug.js:16 language         (&ul)   en-us
VM49 analytics_debug.js:16 location         (&dl)   https://site-name.com/foundation/donate/give-online?t=b2d87d89-e000-4457-8e43-xxxxxxxx
VM49 analytics_debug.js:16 referrer         (&dr)   https://payments.blackbaud.com/Pages/SecurePayment.aspx?t=b2d87d89-e000-4457-8e43-xxxxxxx
VM49 analytics_debug.js:16 screenColors     (&sd)   24-bit
VM49 analytics_debug.js:16 screenResolution (&sr)   1920x1080
VM49 analytics_debug.js:16 title            (&dt)   Foundation Donation Form
VM49 analytics_debug.js:16 trackingId       (&tid)  UA-XXX-XX
VM49 analytics_debug.js:16 viewportSize     (&vp)   1313x937
VM135:29 {transactionId: "b2d87d89-e000-4457-8e43-xxxxxxxxx", transactionTotal: "78.02"}

但是,电子商务数据仍然没有流向Google Analytics(分析)(自实施此代码以来,我已经等待了48个小时以上)。有人可能会发现我在做什么错吗?谢谢。

1 个答案:

答案 0 :(得分:0)

对于将来在此方面苦苦挣扎的人来说,问题实际上很简单。我只是在donationObject中使用旧版Google Analytics(分析)的键名。更改donationObject可以使数据流动:

var donationObject = {
   "transaction_id" : guid,
   "value" : totalDonation
}