Google Analytics电子商务代码添加

目的:主要用于跟踪购物车,可以在谷歌分析师中反馈订单号订单金额信息。

页面:http://www.yoursite.com/flow.php?step=checkout

配置方法:详见示例简化后添加代码

电子商务代码使用指引

参考地址:https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce?hl=zh-CN#General

使用谷歌Analytics(分析)跟踪电子商务的基本过程中总结了三个用于跟踪您网站上的电子商务交易所需的方法。

应该在你的购物车或电子商务软件按照顺序调用这3个方法。

1: Createa transaction object.  创建一个交易对象

Usethe _addTrans()method to intialize a transaction object. The transaction object stores all therelated information about a single transaction, such as the order ID, shippingcharges, and billing address. The information in the transaction object isassociated with its items by means of the order IDs for the transaction and allitems, which should be the same ID.

用_addTrans()方法来初始化一个交易对象,这个对象储存了单一个交易所有相关的信息,譬如orderID 订单号,shipping charges运费和billingaddress帐单地址。这些交易对象信息都是用order IDs订单号来关联所有的物品。必须是同一个订单号。

2: Add items to the transaction.  交易里面添加物品(产品)

The_addItem()method tracks information about each individual item in the user's shoppingcart and associates the item with each transaction via the orderIdfield. This method tracks the details about a particular item, such as SKU,price, category, and quantity.

_addItem()方法跟踪购物车每一个单独物品信息并且通过同一个orderID字段来关联到同一个交易号。这个方法用来跟踪特别的信息,譬如sku号,价格,分类和数量。

3: Submitthe transaction to the Analytics servers. 提交交易到分析师服务器

The _trackTrans()method confirms that a purchase has occurred, and all data that has been builtup in the transaction object is finalized as a transaction.

_trackTrans()方法确认一次购买发生之后,所有信息都已经在交易对象里面完成就提交给服务器。

示例代码

https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce?hl=zh-CN#General

 

<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',           // 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 - required
    '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';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<body>

  Thank you for your order.  You will receive an email containing all your order details.

</body>
</html>

 示例代码中文注释

添加一个交易对象

  _gaq.push(['_addTrans',
    '1234',          // order ID – required 订单号必须
    'Acme Clothing',  // affiliationor store name 联署或商店名(非必须)可以为空值’’
    '11.99',         // total – required 金额必须
    '1.29',           // tax 税(非必须)可以为空值’’
    '5',              // shipping 运费(非必须)可以为空值’’
    'San Jose',       //city 城市(非必须)可以为空值’’
    'California',     // stateor province 省(非必须)可以为空值’’
    'USA'             //country 国家(非必须)可以为空值’’
  ]);

添加每一个物品

   // additem might be called for every item in the shopping cart 购物车里面每一个物品都需要遍历一次
   // where your ecommerceengine loops through each item in the cart and
   // prints out _addItem foreach
  _gaq.push(['_addItem',
    '1234',          // order ID – required 订单号必须
    'DD44',          // SKU/code – required sku必须
    'T-Shirt',        // product name 物品名称 可以为空值’’
    'Green Medium',   // category orvariation 物品类别 物品分类 可以为空值’’
    '11.99',         // unit price – required 价格必须
    '1'              // quantity – required 数量必须
  ]);

_gaq.push(['_trackTrans']); //submits transaction to the Analyticsservers

提交流水到分析师服务器

电子商务代码简化之后要添加的代码为

_gaq.push(['_addTrans',$orderId,$affiliation,$sumOfGoodsFee,$tax,$shippingFee,$city,$state,$country]);

_gaq.push(['_addItem',$orderId,$skuId,$productName,$productCategory,$unitPrice,$quanity]);                

_gaq.push(['_trackTrans']);

备注:

1.    $affiliation和$tax无此项目可以直接设置为空值’’。

2.    添加物品时要遍历购物车每一个物品
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值