I'm using Angulartics to implement events and tracking on my site.
See: https://github.com/luisfarzati/angulartics
We're currently injecting the analytics tracking code with GTM. If we don't inject the snippet, there's no traffic visible in Analytics.
See snippet:
<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-XXXXXXXXX', 'auto');
</script>
The events are sent and everything seems to work in GTM. We don't need to use
ga('create', 'UA-XXXXXXXXX', 'auto') in the injected code because the UA ID is already set in GTM, so there is some magic Google is doing with linking up GTM with analytics.
Basically, without (//www.google-analytics.com/)analytics.js loaded, we see no traffic.
I thought this would work, but clearly it doesn't.
Can anyone help me out with this?
Thanks
Related
I am trying to implement a Google Analytics user-level custom dimension on a site.
I have read here that the code to do this looks something like this:
ga('set', 'dimension2', value );
If I include that script in page X, will the hit for page X's page-view include that dimension/value? Or will it only apply to future hits that that user initiates?
Since you're setting a user level scoped CD, it will apply to all previous hits in the session as well.
I'd recommend you do the ga('set') before you perform ga('send'), this way you utilize the pageview hit to set this CD, not the next hit.
Edit:
Your regular implementation looks like this:
<!-- 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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', ...); //do you sets here
ga('send', 'pageview'); //this is the send
</script>
<!-- End Google Analytics -->
Alternatively, you can just run this and just do "set" and "send" separately, though you'd want to execute the set/send very close to when you load the page:
<!-- 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','https://www.google-analytics.com/analytics.js','ga');
**//removed ga(send) stuff**
</script>
<!-- End Google Analytics -->
To verify, use dev tools, look at your networks tab. Search/filter for "collect" you'll see the calls made to GA. Look for the parameters for the call, specificall cd1, cd2, cd3 etc...look for the cd# that's the same index as the cd you've set. Verify the data there is correct.
My only confusion is:
Full code before Adding google tag manager as below ()
(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-65833292-1', 'auto');
ga('send', 'pageview');
Now, for google tag manager code to be added, do I need to add the google tag manager script in addition of the above code or should I remove the tracking code of analytics and add ONLY GTM snippet?
Ideally, you will need to remove all GA (on-page) tracking code including the standard snippet so that you only have the GTM snippet. Everything will be taken care of from within GTM (pageviews, events, other hits). Although leaving the GA code on the page does not cause any errors, it will skew your data.
This is a two part question:
1) Is my new Google Analytics tracking code correct?
2) With the new code, I noticed a HUGE drop in reported sessions. Is this because the tracking code is more accurate or because my tracking code is wrong.
My Domains (example):
www.domain.org
abc.domain.org
cde.domain.org
www.domain.info
abc.domain.info
cde.domain.info
My OLD Google Analytics Tracking 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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-99999999-9', 'domain.org');
ga('send', 'pageview');
</script>
My NEW Google Analytics Tracking 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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-99999999-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', [/^domain\.(org|info)$/]);
</script>
Note: I see my second script doesn't have "ga('send', 'pageview');" could that be the reason for the HUGE drop in reported sessions?
Thanks in advance
Answer to your second question, a huge YES! If you don't have a pageview, then you don't have a way to indicate the start of a session.
Your setup looks correct - just might want to check to see if the auto-link domains accepts regex as I have a feeling it doesn't, ie.:
ga('linker:autoLink', [domain.org, domain.info]);
You might have to list them all out.
Don't forget to add your different domains to the referral exclusion list.
New code is better.
You have drop in number of sessions because now your sessions count in a right way.
Now if user jump from domain.org to domain.info it will be 1 session.
With old code it will be 2 sessions.
i have the following GA code added to my website
<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-67265472-1', 'auto');
ga('send', 'pageview');
</script>
I created a different property to filter my own ip address from being tracked in Google analytics. The only difference in the tracking code is the below
ga('create', 'UA-67265472-2', 'auto');
Can i simply append this code to the end of the existing GA code or would i need to copy the entire new tracking code into the webpage.
Thanks in advance for your replies
You do not need to include the part that loads the analytics.js file multile times.
However if you simply call create with a different account id a second time you will overwrite the existing tracker and all call will be logged to the second account id.
If you need multiple trackers per page you need to create a named tracker, and send a second pageview call (and events etc.) there:
ga('create', 'UA-67265472-2', 'auto' , 'myTrackerName');
ga('myTrackerName.send', 'pageview');
You can this after your existing 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','//www.google-analytics.com/analytics.js','ga');
// default tracker
ga('create', 'UA-67265472-1', 'auto');
ga('send', 'pageview');
// custom name
ga('create', 'UA-67265472-2', 'auto' , 'myTrackerName');
ga('myTrackerName.send', 'pageview');
</script>
To add to the contribution of Eike Pierstorff. When using multiple trackers, it is recommended to start using Google Tag Manager. This will make tracking with multiple trackers much easier.
Especially when you want to track events, custom dimensions, virtual pageviews, ecommerce, etc.
So I have two sites for a client, we'll say www.main.com is their main website and www.signup.com is a site where the user signs up for a certain service.
I recently switched signup.com over to universal analytics so that we could implement cross-domain tracking via the autolink plugin.
I used this article to help me set up the code on each domain.
Here is what I have on main.com:
<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-11865301-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['signup.com'] );
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
NOTE: I'm not sure what 'displayfeatures' is. I was told that a 3rd party vendor had to customize the code at one point and that I shouldn't remove anything.
And here is what I have on signup.com:
<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-11865301-1', 'auto'), {'allowLinker': true};
ga('require', 'linker');
ga('linker:autoLink', ['main.com'] );
ga('send', 'pageview');
</script>
I also have both domains listed in my Referral Exclusion List so that we don't see main.com as referrals for the signup goal.
What's happening now though, is that for almost all of our conversions, the source/medium is showing as (direct)/(none) and the referral path is showing as (not set). We cannot figure out why.
At the time of this posting there are 14 goal conversions for the day. All of them are reporting a referral path of (not set) and 13 of them are reporting a source/medium of (direct)/(none). There is one conversion that has it's source/medium listed as bing/organic, if that is any kind of clue.
I'm not finding a lot of results on the subject in my googling so this is my last resort. Any help would be appreciated.
UPDATE: So I've been researching this heavily for the past 24 hours and have found out more information.
The (direct) or (not set) referral sources are coming from main.com. The reason they are listed as direct or not set referrals is because we have main.com listed in the referral exclusion list. When I turned it off these referrals started coming is as main.com.
It's starting to look more and more like there is no way to take the original referrer from main.com and carry it over to signup.com.
Can anyone confirm or deny this theory?
When you link domains for cross-domain tracking, they should all be included in the autoLink.
ga('linker:autoLink', ['signup.com', 'main.com'] );