Tracking Javascript Events II

Tracking of an javascript event like this won’t work:


echo <a href=\"javascript:popup_scroll('pdf/datasheet/test.pdf','pop_shop',494,550)\"
 class=\"piwik_download\">&raquo; Data Sheet</a>";

So I tried that suggestion : Tracking Javascript Events
like this:


function do_it(target) {
	popup_scroll(target,'pop_shop',494,550);
	piwikTracker.trackLink(target.parentNode.href, 'download');
        return false //cancel default action (load link in current window);
	 }



and


echo "<a href=\"javascript:do_it('/pdf/datasheet/test.pdf')\">&raquo; Datenblatt</a>";

The popup works fine, but the download isn’t tracked either

Thanks Mark

We have always ignored clicks where the anchor href = javascript because it isn’t a link to a download or external site.

Your second example doesn’t work because target.parentNode.href is undefined. Either change your href to a real anchor (e.g., hef="//pdf/datasheet/test.pdf") and add an onclick (e.g., onclick=“doit(target.href)”, or build the URL:

piwikTracker.trackLink(document.location.protocol + ‘://’ + document.domain + target, ‘download’);

That said, trackLink() wasn’t designed as general purpose event tracking. Your mileage may vary.