博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用Google Analytics(分析)跟踪AJAX链接点击
阅读量:2520 次
发布时间:2019-05-11

本文共 2275 字,大约阅读时间需要 7 分钟。

4/22/2011: This blog post was completely rewritten to describe page tracking with Analytics' asynchronous loading method.

2011年4月22日:这篇博客文章已被完全重写,以描述使用Google Analytics(分析)的异步加载方法进行页面跟踪。

With more and more websites becoming completely AJAX-driven, the typical "do this every time a page loads" strategy isn't always enough. This is especially try if you're using Google Analytics or other analytics tracking software. Google is, of course, forward-thinking so they've provided a way to easily track page views of AJAX requests.

随着越来越多的网站完全由AJAX驱动,典型的“每次加载页面时执行此操作”策略并不总是足够的。 如果您使用的是Google Analytics(分析)或其他分析跟踪软件,则尤其可以尝试。 Google当然是有远见的,因此他们提供了一种轻松跟踪AJAX请求的页面浏览量的方法。

Google Analytics JavaScript (The Google Analytics JavaScript)

The current standard for loading Google Analytics is the asynchronous method:

加载Google Analytics(分析)的当前标准是异步方法:

var _gaq=[["_setAccount","UA-#######-#"],["_trackPageview"]];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";s.parentNode.insertBefore(g,s)}(document,"script"));

That bit tracks the initial page load but not subsequent AJAX calls. Any time you want to track a page load, place add the following snippet:

该位跟踪初始页面加载,但不跟踪后续的AJAX调用。 每当您要跟踪页面加载时,请添加以下代码段:

// "_trackEvent" is the pageview event, _gaq.push(['_trackPageview', '/some-page']);

_trackPageview is used again but this time we provide the URL of the AJAX address that was loaded. Using the small JavaScript snippet above allows you to keep track of pageviews just as you would if the entire page reloaded. I'd recommend using this snippet with .

再次使用_trackPageview ,但这次我们提供已加载的AJAX地址的URL。 使用上面的小JavaScript代码段,您可以跟踪页面浏览量,就像重新加载整个页面一样。 我建议将此代码段与 。

旧方法 (The Old Method)

If you're still using the synchronous method of loading Google Analytics, the following snippet will accomplish the same task:

如果您仍在使用同步方法加载Google Analytics(分析),则以下代码段将完成相同的任务:

pageTracker._trackPageview('/some-page');

It's great to know that Google Analytics is as dynamic as your web applications. Allowing developers to track AJAX page clicks prevents the need to code apps just to keep track of statistics.

很高兴知道Google Analytics(分析)与您的Web应用程序一样动态。 允许开发人员跟踪AJAX页面点击次数,从而无需为了跟踪统计信息而对应用程序进行编码。

翻译自:

转载地址:http://gcpwd.baihongyu.com/

你可能感兴趣的文章
llg的农场(farm)
查看>>
Delphi的FIFO实现
查看>>
Anti StrongOD Kernel Mode
查看>>
bootstrap字体图标在谷歌显示正常,在火狐显示异常的问题
查看>>
Luogu CF22C 【System Administrator】
查看>>
【原】使用less实现随机下雪动画
查看>>
Urozero Autumn 2016. UKIEPC 2016
查看>>
ActiveReport使用心得(四):WebForm下的显示类型及数据的导出
查看>>
《精通CSS:高级Web标准解决方案》学习笔记之二:可视化格式模型
查看>>
Flash调用Lua脚本: 五
查看>>
一次oracle大量数据删除经历
查看>>
npm重要知识点梳理
查看>>
Windows 7安装Service Pack 1失败问题
查看>>
How To Move Or Rebuild A Lob Partition
查看>>
请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理解决方案
查看>>
3-STM32物联网开发WIFI+GPRS基础篇(开发板测试-GPRS)
查看>>
CSS教程:彻底掌握Z-index属性
查看>>
C++中值类型形参、指针类型形参和引用形参的探讨
查看>>
css3:bacground-size
查看>>
双系统开机引导菜单修复方法 进win7无须重启|metro引导|双系统菜单名字修改
查看>>