Google analytics event tracking not working - google-analytics

I have this code setup to track image downloads throught Google Analytics.
<a href="/media/37768/CC20100117m001_thumb_2000.jpg"
onclick="pageTracker._trackEvent('Image', 'Download', 'file.jpg');"
class="hi-res track">
Hi-Res</a>
But the events don't ever show up in the GA reports.
I thought maybe the the browser was following the link before the javascript was being run but setting href="#" doesn't work either.
Any ideas?

Your browser may be following the link before Analytics can make the call logging the event. Check out this page for Google's solution:
http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55527

I don't know what your error is but to find out what it is you can:
Install firefox
Click on the link
Go to Tools | Error Console
Look at the error

This doesn't look correct to me--for one thing, you're using 'pageTracker' to call _trackEvent. In fact, _trackEvent is called by an 'event tracker' object, which is instantiated with _createEventTracker.
There are a couple more steps you haven't mentioned so et's go through them all. (There could be more than one correct way to do this--i'm not sure. So what i can do is compare your code with the steps i follow every time i set up Event Tracking, and which so far, have worked every time.)
Enable 'Event Tracking'. (Do this in
your profile.)
Create the 'event tracker' instance and insert it just after the last line of the pageTracker script. This is usually a single line of code that in your case would look something like this:
var ImageTracker = pageTracker._createEventTracker("Image")
Set up the call to the _trackEvent()
method in your html. I think all you
need to do here is replace
'pageTracker' in your code with 'ImageTracker' (the
event tracker instance you created
in step 2 above).

I faced a lot of problem then I realize it's easy steps and want to share with everyone.
First change your script code, link is https://developers.google.com/analytics/devguides/collection/gajs/#quickstart
Second add a button like this.
<>button onclick="_gaq.push(['_trackEvent', 'button3', 'clicked'])">Press<>/button>
Enjoy :)

Related

Not receiving Fragment in Google Analytics

I have a website like this:
https://example.com/path1/path2/#!portal/1
I've inserted the script of ga and I've made the next modification in the code to receive the fragment (after hash #):
ga('send', 'pageview', {
'page': location.pathname + location.search + location.hash
});
But when I check the ga page, in "Behavior/Behavior Flow/Site Content/All Pages" I only have:
https://example.com/path1/path2/
I'm new in ga, am I doing something wrong?
The code you have in your question will work just fine. I think there may have been a temporary glitch affecting hash URLs, but everything seems to be working now, so I'd just try it again.
Also, since it sounds like you're building an AJAX site, I'd recommend taking a look at the developer guide on tracking single page applications with Google Analytics:
https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications
I had the same problem - overriding the page value didn't do anything, despite the fact that this is explicitly mentioned in the documentation.
I finally replaced the hash with another character (two actually I used a double slash //) in the tracking code and used a search-replace filter in the view settings to restore the hash character.
If anybody has a proper solution I'll take it in a jiffy, but this is at least a workaround that does the job.

How to change onClick tracking for Universal Analytics?

On some of the websites I work on there is a facility to generate an online quote. If a visitor wants to generate a quote, they have to complete 4 steps, each with a "next" button at the bottom of the page. The URL does not change when moving on to the next step of the form so a virtual page view is sent each time a "next" button is clicked. This allowed me to set up a goal with funnel to see how visitors interact with the quote form.
This is what the piece of code I'm using currently looks like:
onClick="javascript:_gaq.push(['_trackPageview', '/Quote1']);"
I have now created a new Universal property in analytics where I'm going to set up and check my goals before upgrading the original property from the asynchronous version.
So, my question is, do I need to change this bit of code to work with Universal Analytics? Or will this work with both versions?
I'm a marketing guy and I know very little about coding so I'd really appreciate a response!
Cheers,
Andrew
Yes, you will need to the old code to the new Universal Analytics syntax, which should make a little more sense to you, marketing guy.
The updated code will look like this:
onclick="ga('send', 'pageview', '/Quote1');"
*I removed the javascript prefix from the onclick because it's redundant.

Google tracking code validation doesn't work

So, in order to see interests/demographics/etc on google analytics, I need to make a one line change to my tracking script on the website ( https://support.google.com/analytics/answer/2444872?hl=en&utm_id=ad ). So, I simply copied the code and pasted it in my website's base template. Everything works! Realtime analytics, google's debug script gives no errors, but... when I click demographics tab, or any other one requiring the script change, I need to validate the tracking code. When I click that button, nothing happens... Anyone had similar problems?
My website: http://osrodekzdrowiawskale.pl/
I had the same problem; I knew I implemented the code correctly, still the validation didn't work. I hesitated to press skip, though, but it worked when I did! After that, it said on the web page that it will take 24 hours before data reports start to show.
"If you are certain that you’ve made the correct change, you can click Skip validation."
https://support.google.com/analytics/answer/2819948?hl=en-GB (Solution source)
Edit: Just noticed that the question was solved in the comments.
Check again tomorrow. Can take anywhere to 24 hours for demographic data to start populating.

Google Anlytics monitoring of events doesn't work properly

I've a problem with a function of Google Anlytics monitoring.
I want to track the download of a file on my web site and I wrote the following line:
<a href="/file_download/nomefile.zip" onclick="_gaq.push(['_trackEvent', 'download', 'click', 'myFile']);">
But it seemes it doesn't work correctly. There are some downloads not shown and it seems to work only in a specific region: only tracks click from Italy, for example.
Can you give me any help or suggestion in order to resolve the problem, please?
Ps. I'm sure there are not tracking downloads because some people contacted me for support on the file and no event of download is shown.
The problem with this implementation is that the page gets unloaded before the event is recorded. To solve you can do one of the following:
Use universal analytics. This implementation uses a function call which will get executed before unload.
Wrap the click in a function which will delay the unloading of the page by several hundred milliseconds.

Event conflicts w/ google analytics

I'm a complete newbie to google analytics, new like I was put on a project yesterday and I've been combing through docs trying to figure out what's wrong with this _trackEvent that I'm trying to set up.
Here's the setup:
I have a drupal site that has had some custom events set up. One of the events that we track is outbound links, and that works great. What we want to do is start creating special cases for some of these links. So for example I have a live chat button w/ this code:
<a href='url/to/chat
onclick="_gaq.push(['_trackEvent','LiveChat','btnClick',this.href]);
setTimeout(function(){this.newWindow = window.open(this.href);
this.newWindow.focus();
this.newWindow.opener=window;},200);
return false;"><img alt='Live Chat Software' src='src/url' border='0'></a>
so what I did is ran the calls through the ga_debug.js. This is the output I got
_gaq.push processing "_trackEvent" for args:
"[Outbound links,Click,outgoing/url]": Track Event
Tracking beacon sent!
This means that an event is getting sent on click. So I'm curious why it's sending an Outbound Links event rather than my LiveChat event? Could it be scoping issues? Not sure, as I know the outbound links is defined at a global level. Anyone have any suggestions/insights/opinions? Before berating me about code, I have inherited this project and I'm just trying to understand it better.
thank you,
Brodie
Okay so it turns out that it was a scoping issue. When they had originally set us up the bomb the click event was registered to the body as opposed to being an inline. So that was eating the inline event.
lesson learned: double check scoping
tools that helped
ga_debug.js

Resources