Question

I have outbound links like this in my html:

<a href="http://www.example.com" class="gaLink1" 
target="_blank" onCLick="ga_track_link('action', '123', 'abcde', 'fghij')"> 
<img src="http://www.example.com/image.jpg" alt="image name" height="180" style="max-width:153px;max-height:150px;" />
</a>

So, When there is a click on this image, the link www.example.com should open in a new tab, since there is target="_blank". Also, the onCLick event will call the function ga_track_link which is defined as:

function ga_track_link(action, id, name, source) {
    _gaq.push(['_trackEvent', 'category 1', action, id+': '+name]);
    _gaq.push(['_trackEvent', 'category 2', 'example', source, 15]);
}

This function is defined in the script section at the end of the html (inside the body section)

I'm observing in GA, there both events are tracked (category 1 and 2), but the amount of times that both are tracked is not equal. Category 2 appears almost half of times, which makes me think that the 2nd event is not always being fired.

I found this link http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55527 that suggests to put the function "ga_track_link" in the head section of the html and use a return False in the onClick function.

According to some other answers like When and why to 'return false' in JavaScript? , the return false statement would tell the event (onClick) not to be fired, which is not what I want, since I do want it to be fired but after my 2 GA events were fired.

So, I have 3 questions:

1) Is there any problem firing more than 1 GA event (with _trackEvent) on 1 click? What is the best way to do it?

2) Why Google Analytics link above states that the function should be placed in the head section of the html?

3) Can someone please clarify the "return false" statement's goal and how to use it correctly?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top