Change name of counter Universal Analytics - google-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.

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>

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

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

How to track & filter several languages of one TLD without subdirectories like "/en" in one google analytics property?

Is this impossible? We would like to track one domain with several languages in one Google Analytics property in order to have all the traffic of the different languages in one view (profile). But especially we would like to filter each language in one view (profile). Is that possible and how can it be achieved? The top level domain doesn't have subdirectories for the different languages so we can't filter by country code in the URL. We are using the new analytics universal code. Does anyone have an idea? Thanks for your help!!
I assume there is a language switcher somewhere in your page. You could get the selected language by examining the DOM element that holds the language settings.
HTML for a language switcher might look like this:
<div id="language">
<span class="active">DE</span>
<span>EN</span>
<div>
Assuming you use jQuery (because that makes explaining simpler for me, not because it is necessary) you could select the language:
lang = jQuery('#language .active').text();
Then you could do either a virtual pageview to recored the language as a part of the url path
_gaq.push(['_trackPageview' , lang + "/" + window.location.pathname]);
and set up a request url filter or track the language setting as an event (custom var would not quite work, since you cannot filter by custom var).
Edit: With analytics.js you would of course use ga send:
ga('send', 'pageview', lang + "/" + window.location.pathname);
but the principle is the same.

Upgrading to new asynchrous Google Analytics code - should you do it?

I had read somewhere and have now forgotten that upgrading to the new asynchronous code will not enable one to track actual clicks for downloading items when user stays on the same page and that for tracking that you need to use the old version of GA code.
My question is, is that still the case and does anyone have any other reasons for not upgrading to use the newer asynchronous tracking?
thanks
Hmm...are you sure the "old" version of GA automatically tracked downloads? AFAIK GA never automatically tracked download links, that you always had to attach GA code (like a _trackEvent call) to your links yourself. But in any case, it's pretty easy to do it yourself, so it's really not a big deal. Plus, you get lots of benefits upgrading, and one day it may not even be an option to stick with the old version...
If you have jQuery you can for example do this:
// file types you want to consider a download
var downloadFileTypes = ['pdf','doc','docx','mp4'];
$(document).ready(function() {
$('a').filter(function() {
var ext = $(this).attr('href').split('.').pop().toLowerCase();
return ( $.inArray(ext, downloadFileTypes )>-1 );
})
.click(function() {
_gaq.push(['_trackEvent', 'Downloads', $(this).attr('href')]);
});
});
If you do not have a framework like jQuery, you can still do this easy enough with .getElementsByTagName() and using regular loops and conditions instead of the jQuery conveniences like .filter and .inArray
edit: Some things to note about that example:
the jQuery code was an example to hook the GA code to standard links pointing to the file types you specify in downloadFiletypes. It will only apply to links that exist at the time the code is executed. If you have links that may be dynamically generated on the page later, consider looking into .on() instead of .click()
you will need to make tweaks to matching links you want to consider downloads if they do not point to regular files with extensions. For instance, some websites have a controller script that expects a parameter with an ID and it dynamically serves up a pdf or whatever..if your files are like this, you will have to alter the logic to look for that instead.

Resources