GA异步跟踪:TrackingMethods能否从HEADTag中分离出来

发布于 2024-12-11 04:04:53 字数 1890 浏览 0 评论 0原文

我正在将 Google Analytics 从传统跟踪迁移到异步跟踪。现在,我的常规脚本作为文档详细信息位于结束标记之前。

像这样......

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXXXX-1']);
  _gaq.push(['_trackPageview']);
 (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

稍后在页面中,“靠近”结束 BODY 标记 - 我以编程方式将“_addTrans”、“_addItme”和“_trackTrans”方法推送到方法数组中。这样……

    <script type="text/javascript">
        try {
                _gaq.push(['_trackPageview', '/checkout/order_confirmation.aspx']);
                _gaq.push(['_addTrans',
                  '1234',           // order ID - required
                  'Mountain View',  // affiliation or store name
                  '11.99',          // total - required
                  '1.29',           // tax
                  '5',              // shipping
                  'San Jose',       // city
                  'California',     // state or province
                  'USA'             // country
                ]);
                _gaq.push(['_addItem',
                  '1234',           // order ID - required
                  'DD44',           // SKU/code
                  'T-Shirt',        // product name
                  'Green Medium',   // category or variation
                  '11.99',          // unit price - required
                  '1'               // quantity - required
                ]);
                _gaq.push(['_trackTrans']);

        } catch (err) { }
    </script>

这样可以吗?由于它们在 API 文档中并未详细说明,我的电子商务跟踪是否仍然有效?

谢谢

I'm migrating my Google Analytics from Traditional to Asynchronous tracking. I now have my general scripts located as the documentation details just before the closing tag.

Like this ...

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXXXX-1']);
  _gaq.push(['_trackPageview']);
 (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

Later in the page, "near" the closing BODY tag -- I programmatically push the "_addTrans", "_addItme", and "_trackTrans" methods in the methods array. Like this ...

    <script type="text/javascript">
        try {
                _gaq.push(['_trackPageview', '/checkout/order_confirmation.aspx']);
                _gaq.push(['_addTrans',
                  '1234',           // order ID - required
                  'Mountain View',  // affiliation or store name
                  '11.99',          // total - required
                  '1.29',           // tax
                  '5',              // shipping
                  'San Jose',       // city
                  'California',     // state or province
                  'USA'             // country
                ]);
                _gaq.push(['_addItem',
                  '1234',           // order ID - required
                  'DD44',           // SKU/code
                  'T-Shirt',        // product name
                  'Green Medium',   // category or variation
                  '11.99',          // unit price - required
                  '1'               // quantity - required
                ]);
                _gaq.push(['_trackTrans']);

        } catch (err) { }
    </script>

Is this permissible? Since they are not together as detail in the API docs, will my Ecommerce tracking still work?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画离情绘悲伤 2024-12-18 04:04:53

有用。它不需要位于同一个标签中。您应该注意到,对 _setAccount 的调用仍然必须是第一个运行的。在您的示例中,您正在触发 2 个综合浏览量。第一个使用默认的 document.location.href,另一个使用自定义/虚拟页面视图。这可能不完全是您想要的,您应该每页有一个综合浏览量。

It works. It doesn't need to be in the same tag. You should notice that the call to _setAccount still has to be the first one run. And in your example you're firing 2 pageviews. The first one uses the default document.location.href and the other uses a custom/virtual pageview. That may not be exactly what you want, you should have a single pageview per page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文