开发者

How do I get Google Analytics to track individual images on a slideshow?

开发者 https://www.devze.com 2023-02-20 12:08 出处:网络
I have a jQuery slideshow, I\'m using the cycle plugin. I\'m decent with jQuery, but I don\'t know how I should tie it in with Google Analytics to show me how many times each image is requested.

I have a jQuery slideshow, I'm using the cycle plugin. I'm decent with jQuery, but I don't know how I should tie it in with Google Analytics to show me how many times each image is requested.

I've looked around online but I haven't been able to find any good documentation for it.

Can someone give me a simple example and maybe a link to the documentation supporting the example?

Thanks!

Edit:

The key is just to use this code to send an event:

_gaq.push(['_trackEvent', 'PageLocation', location.href]);开发者_如何学Go

But you need to have the asyncronous syntax of calling Google Analytics, which will probably look something like this:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxx-1']);
  _gaq.push(['_setDomainName', 'site.com']);
  _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>

BTW you might need to wait for the document to be ready / loaded before executing the _gaq.push line :)


I'm not sure why you would want to do this. Analytics is about the page in relation to how the users interact with it.

If you had a random image being shown first on a page it could be useful to know which one is causing the biggest bouncerate, or if your images in the slideshow were hyperlinked and you wanted to know which one is gathering the most click-through to other pages, but the ammount of times an image is loaded is a pretty arbitrary statistic.

Event tracking is probably what you should be looking at, but im unsure of what you are trying to do with the tracking data... if you give a better explanation id be more then happy to help.

http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html

......

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号