Google Analytics - async tracking with two accounts - google-analytics

I'm currently testing GAs new async code snippet using two different tracking codes on the same page;
_gaq.push(
['_setAccount', 'UA-XXXXXXXX-1'],
['_trackPageview'],
['b._setAccount', 'UA-XXXXXXXX-2'],
['b._trackPageview']
);
Although both codes work, I've noticed that they present inconsistent results. Now, we aren't talking huge differences here, only 1 or 2 visits / day every now and then. However, this site is tiny and 1 or 2 visits equates to a 15% difference in figures. Now, the final site has much more traffic, but my concerns are;
will this inconsistancy scale with traffic?
assuming not, is a slight variation in recorded stats an accepted norm?

You can avoid the conflicting cookies by setting a different domain for google analytics.
<script type="text/javascript">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-NNNN-1']);
// primary profile
_gaq.push(['_setDomainName', 'www.domain.com']);
_gaq.push(['_trackPageview']);
_gaq.push(function() {
// create the second async tracker
_gaq._createAsyncTracker('UA-NNNN-2', 'blogTracker');
});
// secondary profile (this is the default domain setup if not specified)
_gaq.push(['blogTracker._setDomainName', 'domain.com']);
_gaq.push(['blogTracker._trackPageview']);
//]]>
</script>
This will keep the cookies separate.
Note: I am using this setup to track events in a second profile to keep my bounce rate numbers accurate. The second profile tracking code is only used on my blog, thus, is not a complete profile on purpose.

Are they from different accounts ?
If so check follow statement from GA website
Multiple Analytics Accounts on a Given
Page Some users want to track the same
page or set of pages in multiple
Analytics Accounts. Analytics is
designed to work effectively with a
single account-to-web-property
relationship. If you have multiple
accounts tracking the same web
property (e.g. page or sets of pages),
both accounts will read from and set
the same set of cookies. This set up
is generally not recommended.

Another thing to consider with tracking in multiple accounts is that any events in the page will be sent to whichever account was set last in the _setAccount call. I spent months wondering why my events weren't showing up under my main account and then realized we had an extra set of tracking code appearing after the main tracking code with a call to _setAccount for the affiliate account. My event tracking code appeared to be working fine, but events never showed up in my account. Moving the affiliate code to before our main tracking code solved the problem.

Related

Which gtag MEASUREMENT_ID to use

I'm a back end developer, sometimes a little fronted, but not a SEO related expert at all.
Now I have to make a full website from top to bottom and I'm stuck with the Google stuff.
First I created a Google Analytics profile, I got the srcipt that I needed to hardcode to all my site.
<script async src="https://www.googletagmanager.com/gtag/js?id=G-MEASUREMENT_ID></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-MEASUREMENT_ID');
</script>
However, a little while later, I started to use Google Ads and it recommended to connect my Analytics page to the Ads page, so I connected them and I got another code that I needed to insert.
The code snippet is almost the same, except the two MEASUREMENT_ID, because now I got a UA-MEASUREMENT_ID.
So, do I have to use both snippets, or just one? If so, which MEASUREMENT_ID should I use?
Or am I screwed up something?
Thanks all the help
The code with UA- (Universal Analytics) and the one with G- (Google Analytics 4) belong to two completely different tracking systems in Google Analytics. If until now you have used UA- you should continue to do so and in parallel track with the new one G-. So you will have two tracking codes at the same time. This is also Google's suggestion not to lose the data history in UA-.

Google Analytics stopped gathering data when migrated to gtag.js

I have an angular.js webapp and I´m using Google Analytics. On 16/11 I migrated my angular webapp from the old universal google-analytics.js script to the new gtag.js. Next day, I stopped to getting analytics information. See the screenshot.
Some considerations:
I just migrated the js in the webapp.
I didn´t change any configuration in Google Analytics.
With the purpose to filter spam or ghost visits in GA, since a long time ago I had a filter that I "expected" to allow analytics only from my site, like:
I have another view without any filter that I have noticed that seems to work. So for some reason the root cause could be the filter.
Also, I have noticed the real-time reports are not working in the filtered view, however, they are working in the not filtered view.
For testing purposes, I have just deleted the filter and the real-time reports are working.
As before the migration, I was gathering analytics, I think there are maybe different problems:
- It looks like the filter is (and was before the migration) preventing the real-time reports to work.
- Apart from the real-time reports, the analytics were working before the migration with the filter, so is there anything that needs to be changed, updated in analytics in order the gtag.js works. Or maybe gtag.js is working in a different way that makes analytics not work with that filter?
- Should I delete the filter in any case? At the moment, I have deleted it and I will observe what happens with the analytics next days. However, if I delete the filter the spam analytics will come back. Maybe there is another filter that has to be applied.
UPDATE:
I attach the Gtag.js script in the website:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-property-1"></script>
<script>
var gaEnv;
switch (window.location.hostname) {
case 'www.domain.com':
gaEnv = 'UA-property-1'; // production
break;
case 'www.test.domain.com':
gaEnv = 'UA-property-3'; // test
break;
default:
gaEnv = 'UA-property-2'; // development
}
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// Config for analytics
gtag('config', gaEnv, { 'send_page_view': false });
// Config for Adwords
gtag('config', 'AW-property');
</script>
As I use Angularjs I hace developed a service to track page views, like:
service.trackPageView = function (url) {
gtag('config', trackingId, {'page_location': url});
/* Old code for google-analytics.js. deprecated with gtag.js
* ga('set', 'page', url);
* ga('send', 'pageview', url); */
};
UPDATE 2: I have installed Google Tag Assistant. It looks like it´s gathering the data and tracking the pageviews. The only strange thing that I see is the alert: This hit is missing the hostname in the URI.
UPDATE 3: As I suspected, when I delete the "include only" my hostname filter in the analytics view, the data is gathered again as you can see in the pic.
So, it´s pretty clear that gtag.js is sendind data from the app to Analytics to the right property.
Now, the only point is that I had that filter that I have deleted to filter the ghost analytics spam. So, I assume it will be back soon. Again to the starting point.
My concern is if it´s maybe related to the info that I send to analytics or maybe the filter was wrong. So, I think I will need help to setup the filter working properly with this gtag.js library.

Cross Domain Tracking with new gtag.js framework

We have a few questions related to the new gtag google analytics tracking code in relation to the cross-domain bi-directional auto linker. In there documentation, they mention you can use one line of code across all sites with unknown origin using the following code,
Documentation for Cross Site
To simplify bi-directional cross-domain tracking further, you can list
all possible domains you want to track in the domains property of the
linker parameter of property's config for each domain, allowing you to
use the same snippet of code on every domain:
On example-1.com, update the property's config:
gtag('config', 'GA_TRACKING_ID_1', {
'linker': {
'domains': ['example-1.com', 'example-2.com']
}
});
On example-2.com, update the property's config:
gtag('config', 'GA_TRACKING_ID_2', {
'linker': {
'domains': ['example-1.com', 'example-2.com']
}
});
There are some inconsistencies in this code, for one, it shows the example-1 and example-2 as using different GA_TRACKING_ID's while all the other examples on the page show the same GA TRACKING ID being used across snippets. We need to use the same piece of code, not multiple pieces. We currently are looking to use this method with ONE gtag code across all sites, not multiple gtag snippets as shown. If you reference the other examples in the link above, you will see they also use one gtag.
We have a situation where we require access to a 3rd site for cross-domain tracking, but the company will not be able to immediately give us access. We do not want to make multiple requests to website #2, so in the meantime can we add all three websites into our cross-domain linking? Will it cause a conflict to add a third website that is not actively tracking basically, but eventually will be added into the mix
Google's old documentation mentions the ability to add more than three domains, does the new gtag framework still have this ability and will it work bidirectionally.
I would assume the proper method of adding bi-directional tracking would be to add it as followed to all sites
gtag('config', 'GA_TRACKING_ID_1', {
'linker': {
'domains': ['example-1.com', 'example-2.com', 'example-3.com']
}
});
Just had a similar dilemma reading through the docs and implementing the solution.
A better step by step overview, that includes a link to the docs you have referenced in your question, is this Cross domain tracking with gtag.js
Code that worked in my case, and that I will mention in my answer bellow, was implemented for a situation where I needed to implement Bi-directional cross-domain tracking across multiple domains. Some of the domains that also needed to be tracked where actually sub-domains (subdomain.example.com), for them you just need to include the root domain (example.com) in the linker parameter domains property array.
Example:
gtag('config', 'GA_TRACKING_ID', {
'linker': {
'domains': ['example.com', 'second-example.com', 'third-example.com']
}
});
And the complete code, including the script src tag if someone needs it:
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', 'GA_TRACKING_ID', {
'linker': {
'domains': ['example.com', 'second-example.com', 'third-example.com']
}
});
</script>
To answer your questions:
You need/have to use one Tracking ID (also known as Property ID). That example snippet confused me as well. But you need to use the same Tracking ID as it gathers data to a single property, and that's what you want with cross-domain tracking. More about Properties here.
I don't see a problem with adding the third website domain to the domains array. The gtag tracking code gets activated only when there is a user on the website where the code is implemented. So in your case, Google Analytics just won't be able to track the traffic on the third domain until you add the appropriate code to it. The tracking on the first two websites where the code IS implemented won't be affected by this.
Yes it will work. Working example displayed above this list.
Yes, that is correct. But you've also included that extra numbering after the Tracking ID in your example that got us both confused initially :)
Of course this isn't all you need to do in order to setup a correct cross-domain tracking. As mentioned in the document referenced at the top of my answer you will also need to:
Create a copy of the reporting views and add a custom filter if you want to get full domain names in your reports. It's easier to differentiate the visits between domains this way (example: you may have an about-us.html page on every domain).
It's important that you add the tracked domains to the Referral Exclusion List. If you don't do this, cross-domain tracking will not work. It will register a single visitor going from the second-example.com to example.com as a new session.
Extra tip from the docs, that proved really helpful:
For quick testing of the above setup, you can use a Chrome extension developed by Google called "Google Tag Assistant".
It saved me a lot of time in debugging the issues.
Especially useful when working on live sites with a lot of traffic. About Tag Assistant Recordings

Issue using Google Analytics (ga.js) and Universal Analytics (analytics.js) at the same time

I have attempted to find this questions answer on this site and a few others. But it does not appear to be working for myself. The following url shows explainations on how to use GA and UA together.
How to use both ga.js and analytics.js?
I've tried this example, with the same account and property (but separate property of course), I have tried this with different accounts but I am constantly only getting 'real-time' hits from the first analytic that is ran. Ie, if I put UA then GA, UA only reports live hit, and visa versa.
Additionally I am getting a message on the screen saying "More than one Google Analytic's scripts are registered. Please verify your pages and templates. "
Sad part is when I Google this, I get many results, but they are all sites that are showing the same symptom :(
Tia Charles
Make sure that your not using the same Tracking ID You need to log them to different web Properties.
_gaq.push(['_setAccount', 'UA-xxxxx-y']);
ga('create', 'UA-xxxxx-z', 'yoursite.com');
Notices how one has 'UA-xxxxx-y' and the other is 'UA-xxxxx-z'

google analytics - multiple trackers on one page (traditional and asynchronous)

I'm writing a widget that will be embedded in other people's websites. I'm using Google Analytics to track all the people that visit all instances of my script on the embedding websites. I understand that the new asynchronous tracking code resolves this problem so that there's no interference with those websites' own Google Analytics accounts.
However, what if my analytics tracking code uses the new asynchronous tracker, and the embedding website is using the legacy (traditional) tracking code? Would there be any interference between these two blocks of code?
My tracker code:
<script>
...
_gaq.push(
['myTracker._setAccount', 'UA-XXXXX-2'], // naming the tracker 'myTracker' to be different from any default tracker already defined
['myTracker._trackPageview']
);
...
</script>
Embedding website's code:
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-1");
pageTracker._trackPageview();
} catch(err) {}</script>
Can pageTracker and myTracker co-exist and register analytics information to their own separate accounts?
As far as official advice goes this is not a supported scenario:
http://www.google.com/support/forum/p/Google+Analytics/thread?tid=3490dc16fec867c5&hl=en
And there are pitfalls:
http://www.lunametrics.com/blog/2009/02/26/pitfalls-tracking-multiple-accounts-ga/
When you say embedded in peoples websites if you mean that your widget lives inside an iframe then you dont need to worry.
If the code is going to be loose in the page then you should try to use a different variable name to the default one so it doesn't clash. This means change the var _gaq = ... to something else and then renaming it throughout your code.
http://www.google.com/support/forum/p/Google+Analytics/thread?tid=5c7a6e5751bf5789&hl=en
I'm not entirely clear on your setup but if it is being inserted into many domains you are going to need to set up multiple GA accounts and use different account numbers per user.
If this is for clients that you have access to then you might consider simply adding an extra user to the report so that you can view all the accounts from one central account:
http://www.google.com/support/analytics/bin/answer.py?hl=en_US&answer=55500&utm_id=ad

Resources