首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google电子商务跟踪Javascript

Google电子商务跟踪Javascript
EN

Stack Overflow用户
提问于 2014-06-17 09:02:58
回答 1查看 135关注 0票数 0

我对谷歌的电子商务跟踪感到困惑,可以在这里找到:https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce。它告诉我将跟踪代码插入到我完成的“谢谢”页面中。

但我的问题是,如果我有不同的项目,其中一个客户不购买多个项目,而只购买一个项目,而另一个客户购买另一个项目,它如何知道总成本或购买了哪个项目?

因此,按照google的示例,我的代码将如下所示:

代码语言:javascript
复制
<html>
<head>
<title>Receipt for your clothing purchase from Acme Clothing</title>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_addTrans',
    '1234',           // transaction 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',           // transaction ID - required
    'DD44',           // SKU/code - required
    'T-Shirt',        // product name
    'Green Medium',   // category or variation
    '11.99',          // unit price - required
    '1'               // quantity - required
  ]);

   _gaq.push(['_addItem',
    '2468',           // transaction ID - required
    'VBE12',           // SKU/code - required
    'Pants',        // product name
    'Small Blue',   // category or variation
    '100.43',          // 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';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<body>

但是,如果我是那个在代码上声明11.99的人,它怎么知道我的总数不是11.99,而是100.43,而不是T恤而是裤子?

任何澄清都将不胜感激,谢谢。

附加信息:我正在使用贝宝,在那里我有3个选项,他们可以购买1个月,6个月或1年的用户。我是否可以从他们那里获得交易ID?或者我创建我自己的事务ID?

EDIT1:

代码语言:javascript
复制
<form onsubmit="trackSubmit('1 Month', 'clickedOn1Month', 'Linkfor1Month')" 
                    onclick="
                        _gaq.push(['_addTrans',
                        '1',           // transaction ID - required
                        '1 Month',  // affiliation or store name
                        '11.99',          // total - required
                        '1.29',           // tax
                        '5',              // shipping
                        'San Jose',       // city
                        'California',     // state or province
                        'USA'             // country
                      ]);" 
                    action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
                    <input type="hidden" name="cmd" value="_s-xclick">
                    <input type="hidden" name="hosted_button_id" value="XXXXXXXXX">
                    <input type="image" src="pay1month.png" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
                    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
                </form>
EN

回答 1

Stack Overflow用户

发布于 2014-06-17 09:33:20

但是,如果另一个客户买了裤子而不是T恤,如果我在代码上声明11.99,它怎么知道我的总数不是11.99,而是100.43呢?

一切都绑定到一个事务,就像它应该在后端应用程序中一样。这不应该是你的后端会计系统。它应该帮助你了解人们在买什么,他们来自哪里(以及其他分析)。

我是否可以从他们那里获得交易ID?或者我创建我自己的事务ID?

这应该是一个id,您可以将其绑定到您的帐户中。

更多信息只是为了说明一下:

JavaScript跟踪器使用JavaScript数组(称为_gaq)形式的队列机制。实际情况是,您可以将函数及其参数(打包为数组)推送到这个全局数组(_gaq)上。在某个时刻,跟踪器脚本将项目从队列中弹出并调用它们,将它们发送到跟踪服务器。

正如您提供的示例一样,需要编写设置所有内容的javascript。

假设您可以控制自己的库存,页面流可能更像这样:

页面加载时的(放入head,async='true‘或页面末尾,然后关闭body标记)

代码语言:javascript
复制
<script type="text/javascript">
  var _gaq = _gaq || [];    //  Creates or references the global queue
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);     //     Sets the google tracking account id
  _gaq.push(['_trackPageview']);    //  Tracks the page

  //    The rest installs the javascript tracker to the page
    (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>

在某个时刻,用户提交您需要控制该提交的表单,并在发送到之前执行以下操作

代码语言:javascript
复制
     _gaq.push(['_addTrans',
    '1234',           // transaction 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
  ]);

您必须生成以上仅对您的公司有意义的值。交易id将用于跟踪其余项目,并可能对您的公司具有或多或少的意义。

然后,您将需要添加与上面相同的事务id的每个项目,并且您再次提供了对您和您的公司有意义的数据。

代码语言:javascript
复制
   // 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',           // transaction ID - required
    'DD44',           // SKU/code - required
    'T-Shirt',        // product name
    'Green Medium',   // category or variation
    '11.99',          // unit price - required
    '1'               // quantity - required
  ]);

最终敲定这笔交易,谷歌的智慧:

代码语言:javascript
复制
_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

然后你把这些东西发送给PayPal。

更多信息:

https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce

https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite#keyComponents

https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24254322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档