Google analytics event tracking on Multiple accounts not working - google-analytics

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>

Related

Google analytics _trackEvent not functioning

I have used _trackEvent for several links. But in google analytics it shows as 0 events and no tracking data are displayed.
Below is the code I used. Do I have to wait 24 hours to view the tracking data? or anything wrong with this?
<a href="https://sites.google.com/site/example/"
onClick="_gaq.push(['_trackEvent', 'Links', 'Bags', 'Mainlinkbags']);"
target="_parent">
tracking code
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-x']);
_gaq.push(['_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)
();
Sometimes it is good practice to use "onmousedown" event instead of "onclick" because "onmousedown" is fired sooner, so GA script has more time to execute event tracking (it's only a few milliseconds difference, but can help). Try it.
http://www.w3schools.com/jsref/event_onmousedown.asp

Google Analytics custom variables not showing up

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.

Pass _trackEvent to multiple analytic tracking codes

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.

Google Analytics custom events not tracking properly

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).

Google Analytics Custom Variables not working

I am trying to log the username of users who are using my system. Unfortunately, I couldn't track by using custom variables. I could track the page visit, but custom variable tracking is not working. Could you please help me? Thanks.
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setCustomVar',1,'UserName','JohnPaul',2]);
_gaq.push(['_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);
})();
</script>
The code is correct and it does track the users now. I just used the similar codes as above and it works now. But I needed to wait 2 days to track the custom variables and it appears in my reports now.
For more than one user, you'll have to use PHP to output user names.
_gaq.push(['_setCustomVar', 1, 'UserName', '<?php get_usernames(); ?>',2]);
***Substitute "get_usernames" with the function for your site that retrieves the usernames.

Resources