I got one domain set up with multiple Google Analytic accounts. The site has different events which were properly tracked in the first profile. But … i'd like to have the events passed to each account without creating an onclick event for each profile.
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-xxxxxxx30-1'], ['_trackPageview'], ['_gat._anonymizeIp'],
['b._setAccount', 'UA-xxxxxxx33-1'], ['_trackPageview'], ['_gat._anonymizeIp'],
['c._setAccount', 'UA-xxxxxxx76-1'], ['_trackPageview'], ['_gat._anonymizeIp']
);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
Thanks for your support
Mike
First, the code snippet you pasted is not correct. The _trackPageview call that follows each tracker will fire a _trackPageview for the first tracker object only. Additionally, your _anonymizeIp setting is being incorrectly used as it needs to come before the first _trackPageview and it applies to all tracker objects.
Corrected syntax:
_gaq.push(
['_setAccount', 'UA-xxxxxxx30-1'], ['_gat._anonymizeIp'], ['_trackPageview'],
['b._setAccount', 'UA-xxxxxxx33-1'], ['b._trackPageview'],
['c._setAccount', 'UA-xxxxxxx76-1'], ['c._trackPageview']
);
For event tracking, you could create a function that does an event tracking call out to all of your trackers in one function call. Something like:
function gaTrackEventAllTrackers(category,action,optLabel,optValue,optInteraction) {
_gaq.push(
['_trackEvent',category,action,optLabel,optValue,optInteraction],
['b._trackEvent',category,action,optLabel,optValue,optInteraction],
['c._trackEvent',category,action,optLabel,optValue,optInteraction]
);
}
Then just call this function in your code or onclick.
Related
I am working on a website, and i want to do record event event on the website. for that i have searched on Google and found Event Tracking. but i how to check whether i am using ga.js or analytic.js and which is better to use and why.
My google Analytic code is:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '[TRACKING_ID]']);
_gaq.push(['_setDomainName',document.domain]);
_gaq.push(['_setAllowLinker',true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
please help me.
Universal Analytics does not use the .push syntax. Instead, it has a function ga().
You apear to not be using universal analtyics you should check this link on how to work with Event Tracking: Event Tracking - Web Tracking (ga.js)
This link should help you understand the diffrence: About Universal Analtyics
I have been running this code for some time now on all pages. This custom variable has never shown up.
Sorry to ask this again, I don't see another post that solves my case. This has to be the simplest case in the world, this is the same code with only the UA changed:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345678-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setCustomVar', 1, 'User', 'jc', 3]);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
I did not modify the (function()...) .. Do you see the problem? I'm using slot 1 with the page level (3) scope. The same code appears on each page for a given user.
_setCustomVar does not trigger a request to GA. _trackPageview does. You have to move the _setCustomVar above the _trackPageview.
Here's the GA output code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA_CODE']);
_gaq.push(['_setDomainName', 'SUBDOMAIN']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackEvent', 'Priority', 'Created (day)', 'Label info', '']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
the trackEvent line seems to be correct...but not tracking for some reason. Is it because I left the value field nil?
For _trackEvent, the value parameter should be an integer. Since it's an optional parameter, you can just leave it out:
_gaq.push(['_trackEvent', 'Priority', 'Created (day)', 'Label info']);
Having a non-integer value will prevent the event from being tracked.
I beleive _trackEvent won't work properly when called from GA tracking code snippet, at least it was not made for such usage. If you want to execute an event after page loads, try calling it for example from onLoad event of your body tag.
Secondly, passing an optional value parametr as '' would make it undefiened, which looks like it could produce an error, so, since it's optional, don't pass it at all.
And there's a delay in GA reportings, data processing takes about 24 hours (you can switch between new and old versions, sometimes one shows data faster than another).
I have multiple accounts on some pages - I am trying to track some events - they fire beautifully when I test them on Fiddler - but they are not coming into my analytics - the code is below - what am I doing wrong? Three days later any help would be GREAT.
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(
//tracking for first
['_setAccount', 'UA-XXXXXX-1'],
['_trackPageview'],
//tracking for second
['b._setAccount', 'UA-XXXXXX-16'],
['b._trackPageview'],
['b._trackEvent'],
['b._trackPageLoadTime']
);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www')
+ '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
<li><a href="#anchor_2" class="gray"
onClick="_gaq.push(['b._trackEvent', 'button3', 'menu', 'clicked']);">link</a></li>
Note that _trackPageLoadTime is deprecated now. You don't need that anymore. Also the event on the top doesn't make sense. Events must have at least two string parameters and they have optional 3rd string parameter and 4th integer parameter.
So your code on the top should look like this:
var _gaq = _gaq || [];
_gaq.push(
//tracking for first
['_setAccount', 'UA-XXXXXX-1'],
['_trackPageview'],
//tracking for second
['b._setAccount', 'UA-XXXXXX-16'],
['b._trackPageview']
Then when you're firing the event you are only sending this to your b account and I believe you want to send to both. So for that reason you should do something like this:
<li>take me somewhere</li>
I'm trying to set a custom variable in my Google Analytics tracking for a very rough form of split testing.
The code I'm using at the end of my 'head' section is
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-xxxxxx-xx'],
['_setCustomVar', 1, 'split', '1', 2],
['_trackPageview']
);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
The page view is tracking fine but I'm not seeing anything other than "(not set)" under the User-defined sub-section of the Visitors section.
Can anyone spot anything wrong? I've had this working before using the older ga.js before the Asynchronous stuff came along.
Thanks.
_setCustomVar data shows up in the Visitors "Custom Variables" report. Only data from _setVar shows up in the "User Defined" report.