discoloser Posted November 2, 2010 Share Posted November 2, 2010 I use google analytics on my website and it works perfectly, except when I want to track the number of downloaded images. The code I use looks like this, and I don't understand why it does'nt work. Someone who knows? <html> <head> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'XX-XXXXXXXX-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> </head> <body> <a href="download.php?dir=images/paris/20100922&file=_MG_1457.jpg" onClick="javascript: pageTracker._trackPageview('/downloads/_MG_1457.jpg');"><img src="images/paris/20100922/_MG_1457_thumb.jpg" /></a> </body> </html> Link to comment https://forums.phpfreaks.com/topic/217543-problem-with-google-analytics/ Share on other sites More sharing options...
trq Posted November 2, 2010 Share Posted November 2, 2010 You want event tracking, not page tracking. http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html ps; The code to instantiate the relevant object and to take care of page tracking should be inserted just prior to your closing </html> tag (along with all other Javascript really). Link to comment https://forums.phpfreaks.com/topic/217543-problem-with-google-analytics/#findComment-1129396 Share on other sites More sharing options...
discoloser Posted November 2, 2010 Author Share Posted November 2, 2010 I followed this (http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55529) but still no success And according to google analytics you should place the tracking code just before the closing </head> tag Link to comment https://forums.phpfreaks.com/topic/217543-problem-with-google-analytics/#findComment-1129412 Share on other sites More sharing options...
trq Posted November 2, 2010 Share Posted November 2, 2010 You never setup a pageTracker object so that example won't work. Your using the newer _gaq object. And according to google analytics you should place the tracking code just before the closing </head> tag Ive never heard of that before. Can you point me to that article? Link to comment https://forums.phpfreaks.com/topic/217543-problem-with-google-analytics/#findComment-1129416 Share on other sites More sharing options...
discoloser Posted November 2, 2010 Author Share Posted November 2, 2010 I found it here: http://www.google.com/support/analytics/bin/answer.py?hl=en_GB&answer=174090&utm_id=ad Once you find the code snippet, copy and paste it into your web page, just before the closing </head> tag*... Anyway, now I use event tracking instead. We'll see tomorrow if it succeeded Link to comment https://forums.phpfreaks.com/topic/217543-problem-with-google-analytics/#findComment-1129430 Share on other sites More sharing options...
trq Posted November 2, 2010 Share Posted November 2, 2010 That is different to there old code then, good to know. Thanks. Link to comment https://forums.phpfreaks.com/topic/217543-problem-with-google-analytics/#findComment-1129432 Share on other sites More sharing options...
.josh Posted November 2, 2010 Share Posted November 2, 2010 assuming you actually added the code to the link's onclick correctly, there's another hoop to jump through that GA fails to mention or consider: more often than not, when you click on the link, you wind up getting taken to the download before the GA code has a chance to trigger. See this post for details. Different question, same principle. Link to comment https://forums.phpfreaks.com/topic/217543-problem-with-google-analytics/#findComment-1129545 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.