Event tracking not working - google-analytics

I am trying to integrate the Google's event tracking on my application using the below script. I can able to see the Events in "Realtime" tab. But I am not able to see the events in "Content" tab.
var _gaq = _gaq || [];
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAccount', 'XXXXX']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackEvent', 'request.fullpath', 'plan_desc', 'plan_code>']);

Are you grabbing the script that defines the gaq function?
var _gaq = _gaq || [];
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAccount', 'XXXXX']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackEvent', 'request.fullpath', 'plan_desc', 'plan_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);
})();
Also, for your event push, are the values you are pushing in supposed to be JS objects? if so, you may want to get rid of the quotation marks.

GA takes a certain amount of time before it translates data that you see in real-time into it's other sections.
It might be that if you have only added the code within 48 hours that results are not ready to view yet.

I would suggest you trying Google Analytics Debugger extension for Chrome to see if tracking events reach google.
https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna?hl=en

If you are trying to use Rails variables in the JS, as request.fullpath looks like one you must make sure you are rendering it out in your templating engine. For example, if you are using ERB, you must call it like this...
_gaq.push(['_trackEvent', '<%= request.fullpath %>', 'plan_desc', 'plan_code>']);
Obviously repeat for the other variables, if they aren't Ruby and are plain JS objects, you need to omit the quote marks around them.

Related

Google Analytics - add third party shopping cart to main domain reports

We would like to track if users sent from our main site to a third party site have bounced or clicked on "Register"
They are willing to put our Analytics code in their pages - both product and registration.
I looked at what is suggested by Google but not clear about a few things.
Our current code on our site:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-nnnnn-1']);
_gaq.push(['_setDomainName', 'none']);
_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>
Code suggested by Google to be on the third party site:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'my-example-blogsite.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
</script>
...
<a href="http://dogs.example-petstore.com/intro.html"
onclick="_gaq.push(['_link', 'http://dogs.example-petstore.com/intro.html']); return false;">
See my pet store</a>
Our code has 'none' in this line: _gaq.push(['_setDomainName', 'none']);
Google's sample code has the URL
_gaq.push(['_setDomainName', 'my-example-blogsite.com']);
Does it matter? Do I need to enter the domain as suggested?
Also Google's code has a link back to our site as follows
onclick="_gaq.push(['_link', 'http://dogs.example-petstore.com/intro.html']); return false;"
Do we need to have a link back? Can we remove the onclick code or will it affect the reporting?
Thanks!
Myalo
You need the onclick event. What is does is to "decorate" the link, i.e. it adds the url parameters that need to be carried over to the other domain (where they are picked up by the Google code and used to continue the session).
Please be aware that the code you are using is horribly outdated. If at all possible switch to the current version (Universal Analytics). While cross domain tracking on Universal Analytics works by the same principle it'S somewhat more elegant (uses a single parameter as opposed to the unwieldy query string for classic GA) and offers a number of helper functions to make cross domain tracking easier.

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.

Uncaught ReferenceError: _gaq is not defined (Google Analytics)

The following message appears when viewing a site page in the chrome debug log.
Uncaught ReferenceError: _gaq is not defined
The page itself is supposed to track an object using the onload event handler and fire a _trackEvent for Google Analytics.
My best guess is that perhaps the ga.js file doesn't load in time and therefore the onload _trackEvent triggered is not caught. the async snippet is being used before the </body> close and the object is positioned in the middle <body>.
(some other posts have referenced jQuery position too but, this might be a red herring)
any assistance greatly appreciated.
From https://developers.google.com/analytics/devguides/collection/gajs/ this code replaces your existing "traditional snippet" with the "latest, asynchronous version, you should remove the existing tracking snippet first."
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-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);
})();
</script>
To see your events come in (to know if this is working) look for "Events" under the "Real-Time" menu option on the left side of the "Reporting" page.
Regarding the position of the async snippet, the GA help page says -
Paste this snippet into your website template page so that it appears
before the closing </head> tag.
My first thought was that JS should be loaded at the bottom of the page to improve page speed. However, the GA async tracking snippet should be loaded in the head, as it will not load the ga.js immediately, and it won't block page execution.(It does this by dynamically adding the script tag to the DOM, which puts it at the back of the queue.)
If, for some reason, you can't move the async snippet to the head, you can define _gaq yourself, like this-
<button onclick="var _gaq = _gaq || []; _gaq.push(['_trackEvent', 'button3', 'clicked'])"/><button>
Had the same problem. You have to define the _gaq array. Just add this after your Google Analytics script in the header:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-X']);
_gaq.push(['_trackPageview']);
You can use the last version of analytics.js instead of ga.js
ga.js is a legacy library. If you are starting a new implementation we
recommend you use the latest version of this library, analytics.js.
For exisiting implementations, learn how to migrate from ga.js to
analytics.js.
Here is an example:
ga('send', {
hitType: 'event',
eventCategory: 'Video',
eventAction: 'play',
eventLabel: 'cats.mp4'
});
Change the Tracking Code to:
<script type="text/javascript">
var gaq;
var _gaq = gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_setDomainName', 'yourdomain.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>

Google Analytics code always reports page name as being "$A"

I have some code (below) that I'm using to track pageviews on Google Analytics. In Google Analytics, all pages end up having the name "$A".
I can't seem to find anyone who has had the same issue and I can't see what I'm doing wrong:
<script type="text/javascript">
(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);
})();
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
_gaq.push(['_trackPageview']);
</script>
<script src="/__utm.js" type="text/javascript"></script>
It sounds like, rather than there being a problem with the tracking code, that the problem is actually with a filter configured for your account.
Specifically, $A makes it sound like you have an improperly configured Reyes based filter that, rather than outputting the regex match, is instead outputting the string "$A", which is meaningless unless you're properly using RegEx.
Can you post detailed information about the profile? In any case, you shouldn.t be filtering on a main profile, since filters cannot be undone, so any configuration errors on your main profile will result in permanently lost data.
My recommendation is to totally remove the filters in pladce, duplicate the profile and apply your desired filters against the duplicate, to mitigate potential data loss problems like this.

Resources