Jump to content

Problem with Google analytics


discoloser

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.