Google Analytics custom events not tracking properly - google-analytics

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

Related

Google analytics event tracking inconsistent

We have implemented GA for tracking clicks as a button and registering them as conversions so we can track them. Our GA include looks like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_setDomainName', 'XXXXXXXX.com']);
_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://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Our code to trigger the event looks like this:
<input type="submit" name="" value="Contact" onClick="_gaq.push(['_trackEvent', 'Property', 'Click', 'Inquiry']);" />
We have the code tracking, but it seems to only pick up a fraction of the conversions. It does record conversions but it doesn't seem to get them all. For instance a couple days ago, we had 17 conversions (we can verify by copies of email) but GA only recorded 1. The site runs always on SSL if that matters.
Can anybody see any obvious reasons as to why we're not tracking all conversions? Thank you!
Google Analytics submits data as parameters on an image request -- the problem is that browsers will cancel pending image requests when navigating to a new page, and it's hit or miss whether the image request gets out before being canceled.
The most common solution involves adding a slight delay (150ms seems to work) after the _trackEvent and before the actual form submit.

Event Tracking Not Showing up in Reports

I am setting up a Javascript timer to grab the time-on-site for one page only with the following event tracking code:
(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);
})();
When I check the Network tab, there are outgoing pings to GA but in GA, there are no reports.
Any help would be greatly appreciated!
Google Analytics code in a web page usually consists of two parts:
Code to load the ga.js analytics code from google-analytics.com
Code to set the analytics account and specify what to track.
The code you've shown is only the first part which loads ga.js. You're missing the code telling Google Analytics what to do/track -- something like
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
It turned out that I needed to simply wait a duration of time before the event tracking turns on. Apparently, with GA, the time is quite variable.

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: Page views tracked but not ecommerce transactions

I'm trying to figure out why the Ecommerce tracking in Google Analytics doesn't seem to work. I can see the page views correctly tracked but no transactions.
Snippet from the confirmation page:
<head>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
_gaq.push(['_setDomainName', '.mydomain.com']);
_gaq.push(['_trackPageview']);
_gaq.push(['b._setAccount', 'UA-YYYYYYYY-1']);
_gaq.push(['b._setDomainName', 'none']);
_gaq.push(['b._addTrans',
'44bbd391-ff38-4f8d-ad68-aec490666151',
'Name',
'1.00',
'',
'',
'',
'',
''
]);
_gaq.push(['b._addItem',
'44bbd391-ff38-4f8d-ad68-aec490666151',
'15',
'test',
'',
'1.00',
'1'
]);
_gaq.push(['b._trackTrans']);
_gaq.push(['b._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>
...
</head>
I'm monitoring the traffic on the page with Firebug confirming that all pixel requests were made and came back OK.
I read about having to wait a few hours, up to one day, before you can see results in GA, but I can see the page views after only waiting a few minutes.
However, the transactions tracked using the same tracker object ("b") are not to be found anywhere(could the Ecommerce reports be refreshing slower than the page views?)
And I finally found the issue. The answer is inconspicuously present on the GA docs page:
_trackTrans()
Sends both the transaction and item
data to the Google Analytics server.
This method should be called after
_trackPageview(), and used in conjunction with the _addItem() and
addTrans() methods.
It's rather easy to overlook but it has such a fundamental effect: transactions won't be tracked.
So yes, always call _trackTrans after _trackPageview!

do i need to call _gaq.push(['_trackPageView']) more than once on a page when using goog analytics asynchronous code?

i am using the vanilla ga asynchronous code thusly, right before end of </head>:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-1']);
_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>
</head>
now, later in the middle of the page i call:
<script>
_gaq.push(['_setCustomVar',
1,
'usertype',
'anon',
2
]);
</script>
the question is, do i need to make another call to _trackPageView?
that is, should i add another
_gaq.push(['_trackPageview']);
...?
Yes, you will need to make another call to _trackPageView in order to count the _setCustomVar. However, this will count as 2 separate page views, which is going to inflate the # of page views for the page. So you should instead move the _setCustomVar up to before _trackPageView is called.
Calling two _trackPageviews will send the custom variable to GA, however this will cause a few negative consequences:
Bounce rate will turn to 0%
pages per visit will increase by 1
To get around this you can:
move the custom variable before the initial _trackPageview, or:
trigger some other call to GA, such as an Event, User Timing Event, Social Event (or last resort, _trackPageview,'fake page name', and filter the 'fake page name' out of all reporting)

Resources