In ga('create' 'ua-' 'auto'), what does 'auto' stand for? - google-analytics

As per the doc , 'auto' in ga('create' 'ua-' 'auto') is described as below.
opt_configObject – An optional object containing configuration field/value pairs.
But, I am not sure, I completely get this.
What is the difference between ga('create' 'ua-' 'auto') and say I give ga('create' 'ua-' 'mysite.com') ?

I agree the method signature and the myriad of valid combination can make it confusing.
ga('create', 'UA-XXXXX-Y', 'auto');
is the same as
ga('create', 'UA-XXXXX-Y', {
cookieDomain: 'auto'
});
More info on using 'auto' for cookieDomain can be found here:
https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#auto
To answer your questions, there's no difference between specifying 'auto' and 'mysite.com' if your site's domain name is 'mysite.com', but there would be a difference if your site were hosted at 'subdomain.mysite.com'.

I had a similar issue awhile back where a client had all of his domains say:
ga('create' 'ua-' 'mysite.com')
That's basically an old method of specifying the cookie to a domain. Might as well change when google changes correct?
I changed them to 'auto' because it simplifies subdomain tracking.
See the official youtube video.
Google YouTube Video

Related

Solving configuration mismatch between Google Analytics and Google Optimize?

So I'm using Google Analytics, Google Optimize, and Google Tag Manager. I also feel that I may be losing my mind.
For performance reasons, we don't want to add the google optimize script through GTM. We want to hard-code it. But every time I try that, the installation doesn't work. Specifically, when I click "Run Diagnostics" on the google optimize setup page, I get an error that says
All Analytics tracking code on the page must have the same tracker configuration settings. [...] The following tracker configuration properties do not have the same configurations: alwaysSendReferrer.
So I go into my handy Analytics debugger, find the alwaysSendReferrer property, and note that it's set to true. Great. I edit the config object that i'm passing to the google optimize init script, and I add alwaysSendReferrer: true. So far so good. Except... I get the same error.
I thought maybe something was wrong with our analytics setup, so I got rid of the hardcoded google optimize script and instead included it via the Google Optimize GTM tag -- which, unexpectedly, worked perfectly. I thought "Okay i'll just find the script that GTM is adding and copy/paste it into the codebase" but of course it's minified within an inch of its life, and untangling that javascript from the rest of the tags would be a whole other endeavor.
I have access to a {{Default UA Settings}} variable in GTM, and google's documentation would really like me to just pass that object to the official "Google Optimize" tag in GTM. That works (I've tested it), but as mentioned, we don't want to do that.
If anyone knows what the Google Optimize config object should look like, that would help me massively.
Right now mine looks like this (with identifying details removed)
dataLayer.push(['config', 'UA-12345', {
'optimize_id': 'GTM-55555',
'linker': { 'domains': ['mywebsite.com <http://mywebsite.com>'] },
'alwaysSendReferrer': true
});
I've tried false, "true", 1, and basically everything else I can think of (I'm quite confident that Google Analytics has this property set to true on our site) -- my only guess is that maybe I'm setting the value in the wrong place and google optimize isn't seeing it. Help?
I know the feeling of losing your mind trying to read through Google documentation!
This is the code I use on pages I wish to run Optimize experiments on:
<head>
...
<!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-PRMQXXX');</script> <!-- End Google Tag Manager -->
<!-- Page-hiding snippet (recommended) -->
<style>.async-hide { opacity: 0 !important} </style>
<script>(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
})(window,document.documentElement,'async-hide','dataLayer',4000,
{'GTM-KL7XXXX':true});</script>
<!-- Modified Analytics tracking code with Optimize plugin -->
<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-99999999-1', 'auto');
ga('require', 'GTM-KL7XXXX');
ga('send', 'pageview');
</script>
...
</head>
Where:
GTM-PRMQXXX is the Google Tag Manager container id
GTM-KL7XXXX is the Google Optimize container id, and
UA-99999999-1 is my Google Analytics id
Note that you need to remove your usual GA script once you add the scripts above.
I hope this helps you!

How can I set a (Google Analytics) Content Experiment (A/B test) with a singular URL?

I want to test whether a variant of my current homepage will perform better (reach a certain goal defined on GA), but I'm struggling to find a good solution.
Let's say the current version (Original) has sections A, B, C in that order. The other version (Variant), though, has sections in the order B, C, A. Note: the top navigation menu (linking to each section's anchor) must reflect this change.
I first considered Client-Side Experiments, which I have done in the past, but I'm worried those wouldn't look good when rendering the site: depending on loading speed, a Variant user would first see section A, and then they would see section A vanish (into the bottom of the page), while they could also notice the menu being changed.
I then considered the regular Experiment mode on Analytics, which asks me to determine two URLs to compare: the Original is my root path (e.g. http://mywebsite.xyz/) and the Variant would be something like http://mywebsite.xyz/home. But I can't orientate half of my users to this different URL - I want to test people who reach my homepage from wherever they may come.
I tried something through the Google Cloud App Engine: publishing two versions of my application, and splitting traffic 50/50 between both (cookie-based). When visiting the root path, one renders the Original, while the other renders the Variant version. Great. It works! But now Google Analytics has no idea which version it's tracking...
What I did: when the page first loads, I send an event with the version identifier as parameter, such as
ga('send', 'event', 'AB_Test', 'A');
// or
ga('send', 'event', 'AB_Test', 'B');
I suppose these would help me check the Events Flow and determine which version reaches more Event goals, but it's still not linked to an Experiment or its features.
Is there any better way to implement this? Am I missing something? It feels too complicated to do something that both the Cloud App Engine and the Analytics should help me achieve. (Thanks for reading, I know it's a huge text)
When I run this type of experiment, I typically try to leverage the API to determine the variation in the backend and then render the template appropriately.
For your current workaround, rather than sending events, I'd recommend instantiating the test on each server and manually setting the variant for each. See code below:
<!-- App 1 / Original -->
<script type="text/javascript" src="//www.google-analytics.com/cx/api.js?experiment=<EXPERIMENT ID>"></script>
<script type="text/javascript">
(function () {
cxApi.setChosenVariation(0);
}());
</script>
<!-- App 2 / Variant -->
<script type="text/javascript" src="//www.google-analytics.com/cx/api.js?experiment=<EXPERIMENT ID>"></script>
<script type="text/javascript">
(function () {
cxApi.setChosenVariation(1);
}());
</script>

How to add Google Analytics cross-domain linker parameters to an URL with javascript (using GTM)?

On our site, we have a couple of buttons that will take you to a different domain but not before we've composed the actual URL with appropriate query parameters in Javascript. What is the best way to add Google Analytic's linker parameter to this URL? We're using the universal script injected by Google Tag Manager.
Ah... found it. Documentation suggests:
ga(function(tracker) { var linkerParam = tracker.get('linkerParam'); })
But the tracker is undefined in my case.
I found the solution in this blog post:
if (typeof(window["ga"]) !== "undefined") {
var firstTracker = ga.getAll()[0];
if (firstTracker) { return firstTracker.get("linkerParam"); }
}
But... on further investigation, I found the root cause: using GTM means that there are potentially multiple trackers active on a page. Hence the single ga-function won't work. I haven't found the exact GTM-compatible way of doing this, but I'll stick with this workaround for now.

Change name of counter Universal Analytics

Help me please.
I have name for my counter Universal Analytics (analytics.js) - clientTracker, but now I want to change it.
Everithing will be Ok with it, or some statistic can be ruined?
Old and new statistic will be counted in counter correct?
Old name (I want to change it):
ga('create', 'UA-XXXXX-Z', 'auto', 'clientTracker')
New name:
ga('create', 'UA-XXXXX-Z', 'auto', 'nonStat')
What you're referring to is the tracker name (GA documentation). The only consideration when changing the tracker name is this: you need to make sure to update every ga command that you want to continue to track.
So, if you change:
ga('create', 'UA-XXXXX-Z', 'auto', 'clientTracker')
to:
ga('create', 'UA-XXXXX-Z', 'auto', 'nonStat')
...you'll also need to change:
ga('clientTracker.send', 'pageview')
to:
ga('nonStat.send', 'pageview')
...and all other instances of:
ga('clientTracker.send', ...
to:
ga('nonStat.send', ...
If yours is more advanced than the typical setup, there may also be other references, such as: ga.getByName('clientTracker'). Make sure these are updated too.
Lastly, check all the platform and third-party integrations you have on your website that might integrate with GA (e.g. a CRM) and make sure they don't rely on the existing tracker name. (A simple way is to search all code sources for the old tracker name using Chrome DevTools on multiple pages of the site, including all form pages.) Any references need to be updated.
That's it; just make sure you replace all references to the old tracker name. Once you change the tracker name in the create command, any other commands still using the old tracker name will stop working.
But first ...
Think about why you want to change the tracker name. Typically the only reason to have a custom tracker name is to have multiple trackers on the page. If you have only one tracker, chances are changing the tracker name is extra effort for no benefit.

Viewing page locally locks up some browsers

I just started replacing my legacy Google Analytics tracking code with the newer "universal" code, and have run into a problem viewing pages locally. I'm not talking about using localhost - I'm talking about simply opening a page like C:\My Documents\whatever\index.html. No problem in FF28. Chrome34 chokes for a while, but recovers. IE11 locks up completely, and it's Task Manager Time.
The reason is clear - when viewing the page locally, it's trying to load the script from file://www.google-analytics.com/analytics.js, which doesn't exist.
Does anyone know how to get around this? I do cross-browser testing before uploading my stuff anywhere - I really need to be able to view the pages locally.
I've found that replacing one chunk of the code snippet appears to work, but I don't know what bad effects it might have. Replacing this:
(window,document,'script','//www.google-analytics.com/analytics.js','ga')
With:
(window,document,'script','http://www.google-analytics.com/analytics.js','ga')
Seems to work, but...?
It appears that my approach will work, but only as long as I'm certain that I will always be serving my pages with the http: protocol, and never with https:
The "book" solution appears to be this:
})(window,document,'script',('https:' == document.location.protocol ? 'https://' : 'http://') +'www.google-analytics.com/analytics.js','ga');
Another workaround to avoid the "local lockup" problem:
if(location.protocol!=='file:') {
(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-999999-9');
ga('send', 'pageview');
}

Resources