谷歌分析和加载使用AJAX的GET请求一个页面 [英] Google analytics and loading a page using ajax GET request

查看:151
本文介绍了谷歌分析和加载使用AJAX的GET请求一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个完全运行使用AJAX移动网站和散列code,基本上每个页面点击一个链接,如

I have a mobile site which completely runs using AJAX, and hash code, basically each page click is a link, such as

<a href='http://some-domain.com/my-page-122.php" hash-id='122'>linkage</a>

这说明网页设计本身存在,它上有谷歌分析页面,但是,在Ajax请求,我只要求加载certein &LT; D​​IV&GT; 上使用jQuery的load()的页面,所以我的问题是说: 因为页面被要求在它完全与谷歌分析code和一切,将它仍然把它记为,即使只有一部分被注入到该页面的页面视图?

Meaning that the page itself exists and it has ON IT google analytics page, HOWEVER, on the ajax request, I only ask to load a certein <div> on said page using jQuery's load(), so my question is: because the page is called for in it's entirety with the google analytics code and everything, will it still record it as a page view even though only a portion is injected to the page?

为什么我问的原因是因为这个网站是越来越每天大约有500独有,我们希望将它更改为新AJAXy形式,所以没有记录分析是一个很大的禁忌。

The reason why I'm asking is because this site is getting around 500 uniques per day, and we want to change it to this new AJAXy form, so not recording analytics is a big no-no.

推荐答案

如果你使用jQuery,您可以绑定到全局 AjaxComplete 触发事件,综合浏览量,每次一个Ajax调用完成:

If you use jQuery you can bind to the global AjaxComplete event to fire a Pageview everytime an Ajax call completes:

jQuery(document).ajaxComplete(function(e, xhr, settings){
  var d = document.location.pathname + document.location.search + document.location.hash;
  _gaq.push(['_trackPageview', d]);
});

如果你每一次更新锚你一个Ajax调用这个会火的完整路径,包括URL的锚部分。

If you update the Anchor every time you do an Ajax call this will fire the full path including the anchor part of the url.

请注意,如果您使用加载内容 .load 有谷歌Analytics跟踪code的话,它会运行一个code和火灾第二综合浏览量。所以你要确保你不要;第•包括Ajax的内容GATC避免双重浏览量

Note that if you load content using .load that has the Google Analytics Tracking code in it, it will run that code and fire a second pageview. So you want to make sure you don;t include the GATC on the ajax content to avoid double pageviews.

这篇关于谷歌分析和加载使用AJAX的GET请求一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆