1
我拼凑了一些我在网上发现的关于在Google Analytics的长文章页面上跟踪滚动距离的想法。我感兴趣的是当用户到达文章的中途标记时记录一个事件,然后再在终点处记录事件。我的代码并不完美,因为它没有考虑页面上的时间(如果用户在页面加载后立即滚动到底部会怎么样?),但是一旦我处理此问题,这是一个容易解决的问题。谷歌分析和_trackEvent:事件不记录到分析
下面的代码在两个console.log()
调用正在跟踪他们应该是什么时候,所以我的假设是_trackEvent调用也可以,但他们不是。没有错误被抛出。他们从未在Google Analytics中显示过。
任何人都可以看到任何明显的错误或漏洞?下面是网站,在这里我使用这段代码:http://www.adlucent.com/blog/
$(document).ready(function() {
if ($(document.body).hasClass('single')) {
var doc_height = $(document).height(),
article_pos = $('#main > article').offset(),
article_height = $('#main > article').height(),
article_half = (article_height/2) + article_pos.top,
article_bottom = article_height + article_pos.top,
scrolled_half = Math.round(100 * article_half/doc_height),
scrolled_whole = Math.round(100 * article_bottom/doc_height);
$(window).scroll(function(){
var scrollPercent = GetScrollPercent();
if (!isScrolledHalf) {
if (scrollPercent > scrolled_half) {
isScrolledHalf = true;
console.log("Reached halfway mark!");
_gaq.push(['_trackEvent', 'Content Engagement', 'Scroll', 'Half']);
}
}
if (!isScrolledWhole) {
if (scrollPercent > scrolled_whole) {
isScrolledWhole = true;
console.log("Reached the end!");
_gaq.push(['_trackEvent', 'Content Engagement', 'Scroll', 'End']);
}
}
});
}
});
function GetScrollPercent(target){
var bottom = $(window).height() + $(window).scrollTop(),
height = $(document).height();
return Math.round(100 * bottom/height);
}
这个词什么意思? –
@Brandon - 对此有何更新?你说你会回来更新你的答案和更多的细节?谢谢! – jmort253
这是固定的.. ?? – shashwat