Specifics of configuring an integration between Universal Analytics and InSales
Copy the link to the article
Copied

The tracking code is added to the "javascript code" field, which is located in the CMS settings, for displaying on all pages of the store.

Example (in all examples XXXXXXXXX will need to be replaced with a real resource identifier!):

<script>
(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', 'XXXXXXXXX', 'auto');

function getCookie(name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([.$?*|{}()[]/+^])/g, '$1') + "=([^;]*)"
));

return matches ? decodeURIComponent(matches[1]) : "";
}

ga('set', 'dimension1', getCookie("_ga"));
ga('send', 'pageview');
</script>

Since InSales does not place this code at the top of the page, you need to duplicate it. Therefore, the transaction uploade code must be placed in the "javascript code" field to be displayed on the successful checkout page by adding the above-mentioned code at the beginning (and duplicating it within the page).

Example:

<script>
(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-XXXXXXXX-X', 'auto');

function getCookie(name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') +
"=([^;]*)"
));

return matches ? decodeURIComponent(matches[1]) : "";
}

ga('set', 'dimension1', getCookie("_ga"));
ga('send', 'pageview');

// UA transaction upload code starts here
ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {
'id': {{order.number}},
'affiliation': 'site.ru', // replace with real domain name
'revenue': {{order.total_price}}
});
{% for item in order.items %}
ga('ecommerce:addItem', {
'id': {{order.number}},
'price': {{item.sale_price}},
'quantity': {{item.quantity}}
});
{% endfor %}
ga('ecommerce:send');
</script>

Important!

When integrating with InSales, in the analytics settings, activate the "Link transactions via Order number" option. In the settings of InSales, you will also see the “Google Analytics code for analyzing visitors on the site” field. You don't need to fill this in: firstly, the GA code will be generated, not the UA code. Secondly, the code will be generated "from the standard module" and will not allow the adding of a unique label entry from the cookie to custom dimension.

Thank you for your feedback.
Was this article helpful?
No
  • Рекомендации не помогли
  • Нет ответа на мой вопрос
  • Текст трудно понять
  • Не нравится описанный функционал
Yes
Next article
Sending a transaction using Daemon Collector
This article describes the principles of transferring transactions using the Daemon Collector technology.
#}