如何让 Google Analytics 跟踪幻灯片上的各个图像?

发布于 2024-10-28 08:32:28 字数 942 浏览 1 评论 0原文

我有一个 jQuery 幻灯片,我正在使用循环插件。我对 jQuery 很熟悉,但我不知道如何将它与 Google Analytics 结合起来,以显示每个图像被请求的次数。

我在网上查了一下,但是我找不到任何好的文档。

有人能给我一个简单的示例,也许还有支持该示例的文档的链接吗?

谢谢!

编辑:

关键是使用此代码发送事件:

_gaq.push(['_trackEvent', 'PageLocation', location.href]);

但是您需要具有调用 Google Analytics 的异步语法,这可能看起来像这样:

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

顺便说一句,您可能需要等待在执行 _gaq.push 行之前准备好/加载的文档:)

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]);

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔书几行 2024-11-04 08:32:29

我不确定你为什么要这样做。分析是关于页面以及用户如何与之交互的。

如果您在页面上首先显示一张随机图像,那么了解哪一张导致跳出率最高可能会很有用,或者幻灯片中的图像是否带有超链接,并且您想知道哪一张获得最多的点击率其他页面,但加载图像的次数是一个相当随意的统计数据。

事件跟踪可能是您应该关注的内容,但我不确定您要尝试如何处理跟踪数据......如果您提供更好的解释,我会很乐意提供帮助。

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

……

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

......

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文