Jump to content

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
https://forums.phpfreaks.com/topic/217543-problem-with-google-analytics/
Share on other sites

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).

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?

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

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.

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.