I'm currently upgrading my company's website across to analytics.js from ga.js
As I understand, _setDomainName, _addIgnoredRef & _trackEvent are deprecated and need updating.
Can anyone confirm that the below is correct please?
gaq.push(['_setDomainName', 'domain.net']);
This should be replaced with:
cookieDomain: 'domain.net',
legacyCookieDomain: 'domain.net'
_gaq.push( ['_addIgnoredRef', 'www.domain.com']);
This now has to be set in the Analytics admin section?
_gaq.push(['_trackEvent', 'Registration', 'New Account', '<organisation>']);
Should be replaced with:
ga('send', {
hitType: 'event',
eventCategory: ' Registration ',
eventAction: ''New Account ',
eventLabel: '<organisation>'
});
Any help would be gratefully received,
Thanks
How does this final example look?
<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-xxxxx', 'domain.net');
ga('send', 'pageview');
ga('send', {
hitType: 'event',
eventCategory: ' Registration ',
eventAction: ''New Account ',
eventLabel: '<organisation>'
});
</script>
You are mostly right except for the cookie domain (at least it'S not obvious from your example that you got it right).
Cookie domain can either be passed as third parameter when you create your tracker:
ga('create', 'UA-XXXXX-Y', 'domain.com');
You can set the parameter to "auto" (IIRC that's the default) and the highest possible level in the domain will be selected as cookie domain (i.e. on subdomain.domain.com auto will set the cookie domain to domain.com).
You can also pass a configuration object with cookieDomain as a property:
ga('create', 'UA-XXXXX-Y', {
'cookieDomain': 'domain.com'
});
which is a useful syntax if you want to set multiple settings at once (you would pass each setting as key/value pair in the configuration object).
As you found out for yourself _addIgnoredRef is now replaced with the referral exclusion list, and your event tracking syntax is fine.
Related
We have three custom dimensions defined in Google Analytics:
ClientId (dimension1): Session-scoped
SessionId (dimension2): Session-scoped
Hit Timestamp (dimension3): Hit-scoped
And these are being fed from an on-page script:
$(document).ready(function() {
(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');
function getClientId() {
try {
var trackers = ga.getAll();
var i, len;
for (i= 0, len = trackers.length; i < len; i += 1) {
if (trackers[i].get('trackingId') === 'UA-XXXXXXXX-1') {
return trackers[i].get('clientId');
}
}
}
catch(e){
//do nothing
}
return 'false';
}
function getSessionId() {
return new Date().getTime() + '.' + Math.random().toString(36).substring(5);
}
function getTimeStamp() {
return new Date().getTime();
}
ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('require', 'displayfeatures');
ga('require', 'linkid', 'linkid.js');
var clientId = getClientId();
var sessionId = getSessionId();
var timeStamp = getTimeStamp();
ga('send', 'pageview', {
'dimension1' : clientId,
'dimension2' : sessionId,
'dimension3' : timeStamp
});
});
</script>
Now, the marketing team tells us that ClientId is not getting captured. They shared data where we had some 24,000 rows, out of which only two had valid client ids. By contrast, Session ID and Hit Timestamp are being captured perfectly.
When I do a quick check on the website (by assigning the code for getClientId() to another temporary function and calling it), I get the ClientId.
I'm really not sure what's causing this to be missed on the live website. Can someone point out something that might be awry?
You should consider loading the GA library as recommended in the <head> section of your site rather than on $(document).ready. This is so that the analytics tracking has the soonest possibility to start tracking user engagements. In addition, if you load the analytics after DOM is ready or after the page has completely loaded, then there is the chance you miss some metrics if, for example, a user lands on your page, and then navigates away before the analytics library has a chance to capture their data.
My eCommerce tracking is working with one exception. All transactions are being grouped as though they came from the same source/medium 'direct/none'.
This is my code;
<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', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-12345678-2', 'auto', 'ecommerceTracker', { 'allowLinker': true });
ga('ecommerceTracker.require', 'linker');
ga('ecommerceTracker.linker:autoLink', ['securedomain.com']);
ga('ecommerceTracker.send', 'pageview');
ga('ecommerceTracker.require', 'ecommerce');
ga('ecommerceTracker.ecommerce:addTransaction', {
id: '123456', // Transaction ID - this is normally generated by your system.
affiliation: '1', // Affiliation or store name
revenue: '99.99', // Grand Total
shipping: '0' , // Shipping cost
tax: '0' }); // Tax.
ga('ecommerceTracker.ecommerce:send');
</script>
I know that at least one of the transactions should of been listed under 'trivago / cpc', as I created this transaction myself.
The only other point to note, is that this transaction process is being carried out across 2 domains.
This is a sample path a user will take;
Visit 3rd party site, in this case Trivago
Click on link, redirecting to our domainname.com
Navigate through our domainname.com pages
Find rooms you want to book
Once you have selected the rooms, navigate to the checkout page
The checkout page is hosted on the domain securedomain.com
From our domainname.com we are redirected to securedomain.com, which contains the same Google Analytics code.
The reservation is saved, and transaction recorded in Google Analytics, but is being shown as 'direct/none'.
One other point to add is that the source domain is http and the destination domain is https. In order to get from the http domain to the https domain, there is a form post.
It may be because the _ga identifier isn't carried through the booking process, so that on the point of conversion the dynamic URL identifier is removed and therefore Google Analytics is referencing the conversion as if it came from a direct source.
I have the same problem and found that this was the case.
See here: https://groups.google.com/forum/#!topic/google-analytics-analyticsjs/kZ8W4iMxAQQ
I´m having trouble figuring out how to track only one specific domain for my project in google analytics. I have a website that runs on two different domains (www.x1.com & www.x2.com)
In the following snippet I´m tracking traffic for both websites (that works) and I´m also trying to track only traffic for x2.com (does not work)
(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-XXXXX-1', 'auto');
ga('create', 'UA-XXXXX-2', 'auto', 'x2Tracker');
ga('send', 'pageview');
ga('x2Tracker.send', 'pageview');
I have two different accounts in my Google Analytics website.
How can I track only traffic for my www.x2.com domain (but not both) ?
You can apply a hostname filter to views of a Google Analytics account, so that it rejects traffic from www.x2.com (for example).
Bear in mind though that it believes x2.com and www.x2.com are different hostnames, so you should exclude them both. This is actually why I recommend an exclude filter, because you might have trouble stacking a pair of include filters.
This is done in Admin - View - Filters - New Filter
I am having a self-referral issue in Google Analytics that I cannot seem to solve. Researching the issue, most conclude the main causes are either:
Tracking code is missing from certain pages.
Incorrect cross-domain or subdomain tracking.
I use an include file with the Universal Analytics code on all pages, so I know missing code cannot be the issue. All user traffic is on a single domain so that cannot be the issue either.
I have also read that sessions expiring can cause self-referrals, but around 80% of referrals are coming from my site so I doubt this is the case.
Here is the tracking code in the include file (not that I think it matters, but I'll include it anyway):
(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-XXXXXX-X', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview');
The only other suggestion I have found is that absolute links could be causing the issue. I am tempted to say this could be the case, as I have noticed the main pages causing self-referrals use absolute links for navigation.
I just finished reading about Google Analytics cross-domain linking. All that has done for me is created more questions. I'm hoping to get some help understanding it all.
Our portal site is hosted at http://aq3.processmyquote.com. We create new websites using the first subdirectory as the site name. All secure traffic is directed to https://aq3.processmyquote.com/. For unsecured traffic, we allow our clients to specify an alternate domain name to use for their pages.
We have a single univeral analytics account for the entire site, and views for each client portal. Our issue is that sites which use an alternate domain name are getting tracked as referrals, and we're losing the organic keywords.
Here are some examples: http://www.autoquoter.com, http://www.idriveaffordable.com, http://www.venamex.com
Google's documentation on this states that I should include the autolinker on the main site, and add allowlinker on the secondary sites. How does that work with a web portal? The same tracking code is inserted into each site. Is it ok to just list all the possible domains when creating the tracker?
(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-XXXXXX-20', 'auto');
ga('require', 'linker');
ga('linker:autoLink',['www.autoquoter.com',
'www.idriveaffordable.com',
'www.venamex.com']);
ga('send', 'pageview');
This would be added to all of the sites, since they are all pointing to the same web site. The only difference is that the sites are skinned independently. I'm not sure how I would add the destination ga create code or if I even need to.
ga('create', 'UA-XXXXXX-X', 'auto', {
'allowLinker': true
});
Well, I've figured this one out on my own. I'm adding my answer here to help anyone else who may encounter the same issue. In the scenario above, it's important to consider that the purpose of cross-domain tracking is to pass the analytics cookie to the next web site.
Let's say that a user landed on http://www.autoquoter.com and enters a zip code to start the quote wizard. The action of that form needs to be secure so it uses the secure domain name, https://aq3.processmyquote.com/... (the full url is omitted for brevity).
In order to pass the analytics cookie to this url, the url needs to be modified to append a _ga parameter to the query string. This is what the google autoLinker does. It just needs a little help to know which links in the page to modify.
<script type="text/javascript">
(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-XXXXXX-20', 'auto', { 'allowLinker': true });
ga('require', 'linker');
ga('linker:autoLink',['aq3.processmyquote.com']);
ga('send', 'pageview');
</script>
Notice that we also can include { 'allowLinker': true }, so that the current page would process an incoming _ga parameter if it exists. On each page, I include the domain names of all possible links in that page. So, if I'm on a secure section of the site, I can only go back to the domain name for that client's portal. In this example, that would be autoquoter's domain name. While we could add all the possible domain names, it's not needed. You only need to include the names that would occur in actual links on that page.
ga('linker:autoLink',['www.autoquoter.com']);
I hope that helps someone. If you have any questions about this, add a comment and I'll try to help.