How to implement e-commerce tracking
E-commerce tracking with AFS Analytics
Thanks to the analytics.js library, AFS Analytics, web analytics solution, offers numerous features making the tracking of an E-Commerce website a breeze. This means, the capture of transactions and the generation of analyzes, to monitor the performance and the evolution of the generated revenues. The installation of AFS Analytics can boost the efficiency and return on investment of online shops.
This guide explains how to use the various e-commerce functions offered by the analytics.js library.
The benefits of implementing e-commerce tracking
Implementing transaction tracking on your site will give you access to many reports:
Thanks to all these analyzes, you will see in real time the trends of the day, the duds and the items that sell well.
What are the steps of a successful transaction?
Let's briefly review the steps involved in sending a transaction to AFS Analytics.
Note: The "thank you page" is very important because it is on this page that you must add the AFS Analytics code for sending data. Once the data is received by AFS, it will be processed in real time.
The javaScript code to add to the Thank Page
.The transmission of transaction data takes place in three steps. You must first verify that the AFS Analytics tracking code is present on the page.
The different steps of sending a transaction:
1. Add transaction
The first step is to specify the transaction data. We use the command
aa('set', 'addTransaction', {
'Id': '1234567',
'Affiliation': 'storename',
'Revenue': '120.90',
'Shipping': '12 .65 ',
'Tax': '5.55',
'Currency': 'EUR'
});
The addTransaction fields
Only the
This is the unique identifier of the transaction. If the value is
The name of the store or affiliate where the transaction originated. Example: 'Toys and Co'
The "revenue" field
This field specifies the total revenue of the transaction excluding tax and excluding shipping costs. AFS calculates the total of the transaction by adding
This field specifies the transport cost. This is a numeric value, the decimal part is separated by a point.
The "tax" fieldThis field specifies the total taxes. In Europe, it is Value Added tax or VAT. This is a numeric value
The "Currency" field
This field indicates the currency of the transaction. It's the ISO code 4217, which is a 3-letter code. For example:
As always it is possible to use the simplified version:
aa('set', 'addTransaction', id ', affiliation, revenue, shipping, tax, currency);
aa('set', 'addTransaction', '1234567', 'storename', '120.90', '12.65', '5.55', 'eur');
2. Add a list of items ordered.
Once you have specified the transaction details, you can specify the items ordered.
We use the command
aa('set', 'addItem',
{
'Id': '0',
'Name': 'Product1',
'Sku': '001',
'Category': 'cat1',
'Price': '100',
'Quantity': "1"
});
The "id" field
The id field is the identifier of the transaction. The identifier is therefore the same as the one set for
This field specifies the name of the item.
The "sku" fieldThis field specifies the reference or code of the item.
The category fieldThis field specifies the category in which the item belongs.
The "price" fieldThis field specifies the price of the item by unit. The decimal part must be separated by a dot.
The "quantity" fieldThis field specifies the quantity purchased. This is an integer value.
The fields
aa('set', 'addItem', 'id', 'name', 'sku', 'category', 'price', 'quantity');
aa('set', 'addItem', '1234567', 'Drone Aircraft', 'SKU00358', 'Drone', '256.56', '1');
3. Sending data to AFS Analytics
Once the whole data is specified, it's time to send it to AFS Analytics. This is the last step and sending is done using the command
aa('send', 'ecommerce', [callback], [params];
</code>
<p>
The <mtag>callback</mtag> and <mtag>params</mtag> arguments are optional.
</p>
<b>Sending all the data:</b>
<code<
aa('send', 'ecommerce');
Example of complete code on a "thank page":
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['AfsAnalyticsObject']=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','//code.afsanalytics.com/js/analytics.js','aa');
aa('create', 'XXXXXXXX', 'auto');
aa('send', 'pageview',’titleindex’,’Thank You’);
aa('set','addTransaction','1234567','Toys Shop','417.55','15.50','86.61');
aa('set','addItem',{'id':'1234567','name': ‘Magic doll’,'sku': '00252','category': 'girl toys','price': '125.56','quantity':"1"});
aa('set','addItem',{'id':'1234567','name': ‘bear plush’,’sku': '00582','category': ‘Plush’,'price': '35.99','quantity':"1"});
aa('set','addItem','1234567','Drone’,'00358','Drones','256','1');
aa('send','ecommerce');
</script>
Case where the thank you page is hosted on the e-commerce platform
If the thank you page is hosted by the payment platform, you must add the AFS Analytics code on this page and specify the visitor's cookie. Generally speaking, when the page is generated by the payment platform, you can add code and retrieve variables previously passed to the payment platform.
1. Getting the visitor's cookie on the page sending on the e-commerce platform:
<script type = "text / javascript">
(Function {i, r, a, m) {i ['AfsAnalyticsObject'] = r;
(I), 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', '// code.afsanalytics.com/js/analytics.js','aa');
// get the visitor's cookie on the order form of your site
// record the cookie in the visitorCookie variable.
Var visitorCookie;
aa('create', 'XXXXXXXX', 'auto');
aa('send', 'pageview');
aa(function (tracker){
VisitorCookie = tracker.get ('cookie.str');
// alert (visitorCookie);
});
</ script>
2. Sending the cookie to the e-commerce platform:
When sending the data to the e-commerce platform, you add a variable containing the
https://www.maplateformedepaiement.com/?.... &mavariable=visitorCookie
3. Recovery and transmission of the visitorCookie variable
.Recovery and transmission of the visitorCookie variable to AFS Analytics on the thank you page hosted by the payment platform.
// code on the page on the 'thank page' hosted by the payment platform.
<script>
//The way to retrieve the variable depends on the ecommerce or payment platform
var visitorCookie=GetVariable("mavariable");
</script>
...
...
//We add the AFS Analytics code
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['AfsAnalyticsObject']=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','//code.afsanalytics.com/js/analytics.js','aa');
aa('create', 'XXXXXXXX', visitorCookie); //Tip: we send the cookie to AFS Analytics.
aa('send', 'pageview','titleindex','Thank page');
//We send the transaction data
aa('set','addTransaction','1234567','Toys Shop','417.55','15.50','86.61');
aa('set','addItem',{'id':'1234567','name': ‘Magic doll’,'sku': '00252','category': ‘girl toy’,'price': '125.56','quantity':"1"});
aa('set','addItem',{'id':'1234567','name': ‘Bear plush’,'sku': '00582','category': ‘Plush’,'price': '35.99','quantity':"1"});
aa('set','addItem','1234567',’Drone’,'00358','Drones','256','1');
aa('send','ecommerce');
</script>
The PHP API
In some cases, it is not possible to execute "JavaScript" code, for example when transactions are managed by a
By AFS Analytics, Wednesday, May 17, 2017