середа, 22 жовтня 2014 р.

RegNow (DR MyCommerce) and GA Universal Analytics ECommerce integration

Задача: видеть прямо в аналитике продажи (транзакции) вашего веб сайта и их источник (компанию, PPC ключевое слово, реферал и т.д.) Данный пример привязан к RegNow (MyCommerce), но его несложно адаптировать под другого провайдера. Если у кого-то есть пример для палки - поделитесь пожалуйста.

Urchin tracking - Тоже самое для urchin аналитики
http://blog.klimenko.kiev.ua/2013/04/regnow-digitalriver-custom-tracking.html



Кусок кода ниже нужно вставить
<script type="text/javascript">
try
{

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');


ga('create', 'UA-XXXXXXX-X', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('require', 'ecommerce', 'ecommerce.js');
ga('linker:autoLink', ['domain.com']);// Domains that are linked from this page.
ga('send', 'pageview'); // Send hits after initializing the auto-linker plug-in.


ga('ecommerce:addTransaction', {
  'id': '<show-var name="orderid"/>', // Transaction ID. Required
  'affiliation': 'RegNow', // Affiliation or store name
  'revenue': '<show-var name="order_total"/>', // Grand Total
  'shipping': '<show-var name="order_shipping"/>', // Shipping
  'tax': '<show-var name="order_tax"/>' // Tax
});

ga('ecommerce:addItem', {
  'id': '<show-var name="orderid"/>', // Transaction ID. Required
  'name': '<show-var name="dynavendor_name"/>', // Product name. Required
  'sku': '<show-var name="dynavendor_item"/>', // SKU/code
  'category': '<show-var name="dynavendor_category"/>', // Category or variation
  'price': '<show-var name="dynavendor_price"/>', // Unit price
  'quantity': '<show-var name="dynavendor_quantity"/>' // Quantity
});

ga('ecommerce:send');

} catch(err) {}

</script>


Базируется на нижеприведенной документации MyCommerce
Based on the following MyCommerce documentation

https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce


Custom Fields of Order Items
This feature allows limited ability to customize the content of the script based on order items' custom fields. The custom fields can be denoted by variables orderitem[field name]_ in the script and can be used in<show-if> and <show-var> tags. For example, a product can have 2 custom fields "AFFL" and "MSG_ID" defined in product configuration file:
<product-configuration>
  <fields>
    <hidden field="affl" display="affl"/>
    <hidden field="msg_id" display="msg_id"/>
    ...
The tracking script can be written to include certain content only when the fields have values:
<script type="text/javascript">
  <show-if var="orderitem_AFFL" condition="notEmpty" test="">var affl='<show-var name="orderitem_AFFL"/>';</show-if>
  <show-if var="orderitem_MSG_ID" condition="notEmpty" test="">var msg_id='<show-var name="orderitem_MSG_ID"/>';</show-if>
</script>
Others
Field Name
Comment
Usage in The Script
Order ID
The order ID.
<show-var name="orderid"/>
Price
The price of a product in the order. Only available when the order contains products from a single vendor (except v1234). This is the unit price of a non-CD (custom CD solution) product from that single vendor in the order. In case multiple eligible products are in the order, an eligible product will be picked at random
<show-var name="dynavendor_price"/>
Product ID
The product ID of a product in the order. Only available when the order contains products from a single vendor (except v1234). This is the unit price of a non-CD (custom CD solution) product from that single vendor in the order. In case multiple eligible products are in the order, an eligible product will be picked at random. The choice of product should match that of the Price field
<show-var name="dynavendor_item"/>
Order Total 
Total Amount Of order 
<show-var name="order_total"/>
Tax
Tax
<show-var name="order_tax"/>
Shipping
Shipping Chargers 
<show-var name="order_shipping"/>
City 
City
<show-var name="order_city"/> 
State 
State
<show-var name="order_state"/>
Country 
Country
<show-var name="order_country"/> 
Product Name 
The product Name of a product in the order. Only available when the order contains products from a single vendor (except v1234).  In case multiple eligible products are in the order, an eligible product will be picked at random. 
<show-var name="dynavendor_name"/> 
Product Category
The product Category of a product in the order. Only available when the order contains products from a single vendor (except v1234). In case multiple eligible products are in the order, an eligible product will be picked at random. 
<show-var name="dynavendor_category"/>
Product Quantity 
The product quantity of a product in the order. Only available when the order contains products from a single vendor (except v1234). In case multiple eligible products are in the order, an eligible product will be picked at random. 
<show-var name="dynavendor_quantity"/> 












Here is how to upgrade your GA ecommerce tracking to universal analytics
https://developers.google.com/analytics/devguides/collection/upgrade/reference/gajs-analyticsjs




Немає коментарів: