XML 文件中的 Google Analytics 脚本

发布于 2024-08-31 18:03:08 字数 1510 浏览 6 评论 0原文

我想知道是否可以在 xml 格式的文件中添加电子商务分析标签?

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_addTrans',
    '1234',           // order ID - required
    'Acme Clothing',  // affiliation or store name
    '11.99',          // total - required
    '1.29',           // tax
    '5',              // shipping
    'San Jose',       // city
    'California',     // state or province
    'USA'             // country
  ]);

   // add item might be called for every item in the shopping cart
   // where your ecommerce engine loops through each item in the cart and
   // prints out _addItem for each 
  _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']); //submits transaction to the Analytics servers

  (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';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
  })();

</script>

I would like to know If I can add my ecommerce analytics tags inside an xml formated file?

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_addTrans',
    '1234',           // order ID - required
    'Acme Clothing',  // affiliation or store name
    '11.99',          // total - required
    '1.29',           // tax
    '5',              // shipping
    'San Jose',       // city
    'California',     // state or province
    'USA'             // country
  ]);

   // add item might be called for every item in the shopping cart
   // where your ecommerce engine loops through each item in the cart and
   // prints out _addItem for each 
  _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']); //submits transaction to the Analytics servers

  (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';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
  })();

</script>

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

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

发布评论

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

评论(2

与他有关 2024-09-07 18:03:08

确保此类内容不会引起冲突的最简单方法是将其包装在 标签。

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<script type="text/javascript">
<![CDATA[
  //javascript
]]>
</script>

The easiest way to ensure this kind of content will not cause conflicts is to wrap it in a <![CDATA[]]> tag.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<script type="text/javascript">
<![CDATA[
  //javascript
]]>
</script>
木緿 2024-09-07 18:03:08

您确定您的建议确实有效吗?我尝试过类似的方法,但 Javascript 永远不会被执行。

不确定我是否做错了什么或者您的想法是否未经测试。

Are you sure your suggestion actually works Oded? I've tried something similar and the Javascript never gets executed.

Not sure if I'm doing something wrong or whether your idea was untested.

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