Analytics
3K members online now
3K members online now
Learn how to set up goals and Ecommerce tracking, verify accuracy of attribution traffic sources, and discuss funnel visualization, Multi-Channel Funnels, the Goal Flow Report, and Enhanced Ecommerce
 
Guide Me
star_border
Reply

Analytics eCommerce tracking for selected accounts on multiple domains

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

We are running multiple individual websites (different domain names) that use common code to process orders.  By default, all websites have the following Google Analytics script installed to capture aggregated data for all sites.

 

UA-11111111-1 - eCommerce tracking is disabled in Google Analytics

UA-22222222-1 - eCommerce tracking is enabled in Google Analytics

 

<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-11111111-1', 'auto', { 'allowLinker': true });
ga('require', 'linker');
ga('linker:autoLink', ['mysecuredomain.com]);
ga('send', 'pageview');
</script>

 

For selected individual websites we are required to start recording eCommerce data, in terms of total order value.  Therefore, on the selected sites that we are wanting to track the eCommerce data, I've added the following (so we have two copies to Google Analytics tracking code installed, the one above and the one below);

 

<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-22222222-1', 'auto', { 'allowLinker': true });
ga('require', 'linker');
ga('linker:autoLink', ['mysecuredomain.com']);
ga('send', 'pageview'); ga('require', 'ecommerce');

</script>

 

For all these individual sites, they are redirected to a secure domain mysecuredomain.com (for example), where the order is competed and confirmed.  On this confirmation page, I've added the following;

 

<script>

ga('ecommerce:addTransaction', {
id: '<xsl:value-of select="BookingId"></xsl:value-of>', // Transaction ID - this is normally generated by your system.
affiliation: '<xsl:value-of select="Header/AgentId"></xsl:value-of>', // Affiliation or store name
revenue: '<xsl:value-of select="Header/TotalPrice"></xsl:value-of>', // Grand Total
shipping: '0' , // Shipping cost
tax: '0' }); // Tax.

ga('ecommerce:send');

</script>

 

For what I can see, if I enable eCommerce tracking for the GA account UA-22222222-1, the eCommerce data is captured successfully, and no eCommerce data is being tracked on the account UA-11111111-1 (because eCommerce tracking is not enabled).  Also, if I confirm a order on a individual website which doesn't have eCommerce tracking enabled, everything works correctly.

 

My question is this the correct way to approach this requirement, and is it OK to have the ecommerce:addTransaction call on the confirmation page, even though no GA account is tracking the eCommerce data.

 

Also, what happens if both my accounts have eCommerce tracking enabled ?

1 Expert replyverified_user

Re: Analytics eCommerce tracking for selected accounts on multiple domains

Top Contributor
# 2
Top Contributor

Hi Neil,

 

I see a few issues here. The first thing, you need to add the first part of the code only once:

(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','https://www.google-analytics.com/analytics.js','ga');

It is responsible for downloading the analytics.js library and for initializing the ga function.

 

Next thing, if you are using multiple tracker objects (tracking for multiple properties) you need to name the subsequent ones. These are called named trackers.

ga('create', 'UA-11111111-1', 'auto');
ga('create', 'UA-22222222-1', 'auto', 'newTracker');

 

Set parameters for each:

ga('require', 'linker');
ga('newTracker.require', 'linker');

ga('linker:autoLink', ['mysecuredomain.com]);
ga('newTracker.linker:autoLink', ['mysecuredomain.com]);

Then you need to send the hits separately for each tracker separately:

ga('send', 'pageview');
ga
('newTracker.send', 'pageview');

 

Also ecommerce: 

ga('require', 'ecommerce');
ga('myTracker.require', 'ecommerce');

ga('ecommerce:send');
ga('newTracker.ecommerce:send');

So to answer your question, you only need to run ecommerce commands for the property you want to track ecommerce in.

 

Hope this helps, let me know if you have questions.


Arnold Majlath, Google Analytics Top Contributor
Was my response helpful? If yes, please accept it as solution.
Circle Me On Google+ | Visit me @ Redfly Digital

Analytics eCommerce tracking for selected accounts on multiple domains

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Hi Arnold,

 

Thanks for you reply.  I understand I only need  load the library once and that I need to name additional trackers.

 

But because me confirmation code is shared at the moment I have no way of knowing if the individual site needs tracking in the confirmation page.

 

So does it cause any problem if I call the send:ecommerce on every case, even if I'm not wanting to track ecommerce transactions ?

 

Thanks

Neil

Analytics eCommerce tracking for selected accounts on multiple domains

Top Contributor
# 4
Top Contributor

Hi,

 

It won't cause any issues, simply the ecommerce data won't be recorded anywhere.


Arnold Majlath, Google Analytics Top Contributor
Was my response helpful? If yes, please accept it as solution.
Circle Me On Google+ | Visit me @ Redfly Digital

Analytics eCommerce tracking for selected accounts on multiple domains

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Hi Arnold,

 

Thanks for your help.  The eCommerce tracking is working with one exception.  All transactions are being grouped as though they came from the same source/medium 'direct/none'.  But I know that at least one of the transactions should of been listed under 'trivago / cpc', as I created this transaction myself.

 

 

Any ideas what the problem is ?

Analytics eCommerce tracking for selected accounts on multiple domains

Top Contributor
# 6
Top Contributor

Hi,

 

It seems that you're losing the referral data somewhere in the checkout process. I'd suggest you to go through the checkout process and record the journey with Google Tag Assistant. You'll see if there is an interruption in the session.

https://support.google.com/analytics/answer/6280771?hl=en

Let me know if you have more questions.


Arnold Majlath, Google Analytics Top Contributor
Was my response helpful? If yes, please accept it as solution.
Circle Me On Google+ | Visit me @ Redfly Digital