I am combining Google Analytics' _trackEvent and _trackPageview into a single call, like the following:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20822178-2']);
_gaq.push(['_setCustomVar', 1, 'My Custom Page View Variable', 'My Value']);
_gaq.push(['_trackEvent', 'My Category', 'My Action']);
_gaq.push(['_trackPageview']);
[...GA snippet insertion...]
This generates two __utm.gif requests to Google. This would be okay except that the request with the _trackEvent information ALSO contains the CustomVar info, which leads me to believe that Google counts the pageview on BOTH requests. I don't want to double count my page requests... so is Google smart enough to throw away the pageview info sent with the _trackEvent call?
Thanks!
It won't double count page views but it is double counting your custom var. If you don't want that, reorder the pushes, make the trackpageview come first, then the custom var, then the event
Related
I have a page in my site "x" that redirect to another site "y".
So I wanted to track that redirect traffic and send it to Google analytics,
by this code :
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
(function(url) {
gtag('event', 'y', {
'send_to': 'UA-xxxxxxxx-x',
'event_category': 'out',
'event_label': url,
'transport': 'beacon',
'event_callback': function(){document.location = url;}
});
})("<?php echo $url; ?>");
When I go to see the Events in Google analytics for "X" I found 5000 event sent.
when I go to see the Referral Traffic in Google analytics for "y" I see only count 2500 mean half the traffic.
These analytics has the same time zone and the date.
So what cause the problems that make double counting the Events?
You're comparing two different metrics (events and users probably). One user can be redirected a million times and it will be still counted on the site Y as 1 user if it happens in one day.
The best QA is to open both sites' real-time analytics and execute the redirect with a parameter which will make sure you're watching your action. Then you should see an event hit on site X and a pageview on site Y.
I have a custom dimension that is being set with a gtag tracking code. I can actually see that the values are being send to GA and can, for example, make dashboard widgets with it.
The odd thing is that when I make a widget with sessions and the dimension it works well, but if I want to make a widget with pageviews and the dimension it returns no data at all.
This is my tracking code:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-0000000-0', {"anonymize_ip":true,"custom_map":{"dimension1":"premium"}});
gtag('set', 'premium', {'premium': 'premium post and not subscribed'});
I've also, instead of using 'set' tried using 'event' but this did not solve the issue. It looks like the custom dimension is not being collected with pageviews, but with sessions only.
Does anyone know if I have to configure it differently to also make it work for pageviews?
Since your custom dimension is configured at the hit level it needs to be associated with either an event or pageview hit. Your code looks like it simply sets the custom dimension value, but it's not followed by a pageview hit call. Try swapping the idea of your calls instead:
gtag('set', 'premium', {'premium': 'premium post and not subscribed'});
gtag('config', 'UA-0000000-0', {"anonymize_ip":true,"custom_map":{"dimension1":"premium"}});
I need to split collecting data for two GA accounts, let`s name them UA-XXXXXXX-1 and UA-XXXXXXX-2. To implement this, I used example code from https://developers.google.com/analytics/devguides/collection/gajs/ (under "Pushing commands to multiple trackers also works" text) and here is my code:
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setCustomVar', 1, 'customVar1', 'cv1', 1]);
_gaq.push(['second._setAccount', 'UA-XXXXXXX-2']);
_gaq.push(['second._trackPageview']);
_gaq.push(['second._setCustomVar', 2, 'customVar2', 'cv2', 1]);
It is working, but I have both custom vars in both accounts. What I really need, is to track customVar1 only for UA-XXXXXXX-1 account, and customVar2 only for UA-XXXXXXX-2 account. Any ideas how to implement this?
First of all, _setCustomVar must come before _trackPageview.
Now to your problem:
This happens because User level custom vars are stored in the cookie. Since both your trackers share the same cookie the second tracker will be sent with the vars set on the first tracker.
You have 3 options.
1) Go With Universal Analytics
The right path here is to use Universal Analytics. Multi-tracking is not officially supported in Classic because it's buggy, as you probably noticed. And things are easy to break.
On Universal all custom dimensions are evaluated server side so this setup is supported. No data is stored on cookies for Custom Dimensions.
eg:
Provided you configured dimension1 on UA-XXXXXXX-1 and dimension2 on UA-XXXXXXX-2 through the Admin interface.
ga('create', 'UA-XXXXXXX-1', 'auto');
ga('send', 'pageview', {
'dimension1': 'cv1'
});
ga('create', 'UA-XXXXXXX-2', 'auto', {'name': 'newTracker'});
ga('newTracker.send', 'pageview', {
'dimension2': 'cv2'
});
More info:
Universal Analytics Advanced Configuration / Multiple Tracking Objects
Universal Analytics Custom Dimensions and Metrics
2) Keep Classic Analytics but, use session level customVars
If you definitively can't move to Universal Analytics and want to keep using Classic you can get around this issue by just using Session Level Custom Vars. To make it work you would only need to change the scope of the custom Var as seen below (from 1 to 2).
Unlike User scoped Custom Vars, Session Scoped CVs don't get stored on the cookie. So you will get around this issue. The downside is that the value will only be valid for that session, not future sessions from the same user.
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
_gaq.push(['_setCustomVar', 1, 'customVar1', 'cv1', 2]);
_gaq.push(['_trackPageview']);
_gaq.push(['second._setAccount', 'UA-XXXXXXX-2']);
_gaq.push(['second._setCustomVar', 2, 'customVar2', 'cv2', 2]);
_gaq.push(['second._trackPageview']);
3) Keep Classic and User scoped CVs but use different cookies per tracker
You can configure GA to create 2 sets of cookies, one for each tracker one at the root domain and one at the subdomain.
If your site is: http://www.example.net setup your trackers like this:
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
_gaq.push(['_setDomainName', 'example.net']);
_gaq.push(['_setCustomVar', 1, 'customVar1', 'cv1', 1]);
_gaq.push(['_trackPageview']);
_gaq.push(['second._setAccount', 'UA-XXXXXXX-2']);
_gaq.push(['second._setDomainName', 'www.example.net']);
_gaq.push(['second._setCustomVar', 2, 'customVar2', 'cv2', 1]);
_gaq.push(['second._trackPageview']);
This MUST to be done in all pages of your site. Not only this one. This will make sure that each tracker uses it's isolated cookieset and customVars won't leak from one to another.
Notice that if your site can be accessed without www.. eg: http://example.net/ this will fail and there is no workaround. You can't create 2 sets of cookies with the same name in the same domain and path. You just can't.
Also if you use _gaq.push(['_setDomainName', 'none']); or _gaq.push(['_setAllowHash', false]);, the above trick won't work and cookies will conflict. Your data will be weird. Just don't do it. You've been warned.
I can't stress enough that this is provided without guarantees and if your data breaks it's on you. Multiple trackers are tricky and that's why it was never officially supported.
More info:
ga.js API Reference Domains and Directories
I have a question about Google Analytics Content Experiments.
My goal type is currently URL Destination.
And we push conversions manually to Analytics after phone call matching, normally it takes one day.
We use this code for pushing conversions.
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'XX-XXXXXXXX-X']);
_gaq.push(['_setAllowAnchor', true]);
_gaq.push(['_trackPageview','/call/conv ']);
What I want to know is how do I push a conversion manually for a specific variation.
Thanks in advance for help.
In GA Content Experiments each variation has it's own url, so you'd simply use the fitting url as the second parameter to _trackPageview:
_gaq.push(['_trackPageview','/call/VARIATION']);
regards,
Eike
I have a search functionality set up in my website, which uses a third party extension retrieve the search results. The search terms are not passed as query parameters.
Below is my sample URL for my search results:
mysite.com/search/results/dGVzdA/
I cannot change the URL to pass the search terms as query parameters.
So I'm trying to send Async Tracking from the google analytics javascript :
<script>
var _gaq= _gaq || [];
_gaq.push(['_setAccount','UA-XXXXXXX-X']);
//Push search query into google analytics
if ({url_segment_1} == 'search' && {url_segment_2} == 'results')
_gaq.push(['trackPageview'],['/search/?q=test']);
else
_gap.push(['trackPageview']);
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
The javascript logic seems to be executing fine, I've tested it by placing alert options. So is there anything that I'm implementing incorrectly with respect to _gaq.push().
Could someone throw light on the same
A couple of errors:
It's _trackPageview, with an initial underscore.
The argument for _trackPageview needs to be inside the array, like:
_gaq.push(['_trackPageview','/search/?q=test']);
[edit] There's also typo: _gap.push should be _gaq.push