使用Google Analytics(分析)跟踪单页网站上的用户

马雷克

最近,我在使用Google Analytics(分析)跟踪“单页网站”上的用户时遇到了问题。我想分享我的解决方案。请参阅下面的答案。

马雷克

最近,我在使用Google Analytics(分析)跟踪“单页网站”上的用户时遇到了问题。我想分享我的解决方案。

- - - 页面布局 - - -

1a. Header with logo and menu (links scroll page down to selected chapter)
2a. Section with big paralax bakground
2b. Chapter header <section><h2>Title 1</h2></section>
2c. Chapter's content <div>content</div>
3a. Section with big paralax bakground
3b. Chapter header <section><h2>Title 2</h2></section>
3c. Chapter's content <div>content</div>
...
Na. Section with big paralax bakground
Nb. Chapter header <section><h2>Title N</h2></section>
Nc. Chapter's content <div>content</div>

- - - 要求 - - -

  1. 算法必须检测页面何时向下滚动,以便用户可以看到所选的章节。
  2. 算法必须检测到用户实际上花费了一些时间来熟悉本章的内容。必须将此事实报告给Google Analytics(分析)。
  3. 当用户滚动浏览章节时,算法无法报告该用户阅读了该章节。

- - 算法 - - -

  1. 等待页面加载
  2. 创建章节列表及其相对于网站顶部边框的位置。
  3. 当所需的章节对用户可见时,必须在一定时间后重新检查此条件,以证明用户实际上花了一些时间阅读内容。
  4. 如果满足上述条件,则将此事实报告给Google Analytics(分析)。

----示例代码-----

<script type="text/javascript">

var scrollstat = []

// Preparing array of chapters and positions
$(document).ready(function() {
    $("section").each(function() {
        var ts = {};
        ts["offset"] = $(this).offset();
        str = $("h2", this).html();
        ts["name"] = "SECTION-"+str.replace(" ","-")+"/";
        ts["checked"] = false;
        ts["timer"] = false;
        scrollstat.push(ts);
     });
});

//Checking that user is still on the same chapter
function doublecheck(ii) {
    scrollpos = $(window).scrollTop();
    max = scrollpos + 300;
    min = scrollpos;
    if (scrollstat[ii].checked == false && scrollstat[ii].offset.top > min
    && scrollstat[ii].offset.top < max) {
        _gaq.push(['_trackPageview', (location.pathname + location.search
        + scrollstat[ii].name)]);
        scrollstat[ii].checked = true;
    }
    console.log(scrollstat[ii].offset.top+','+min+','+max);
    scrollstat[ii].timer = false;
}


//Separate function for setting timer to count 3s
//If user don't scroll to other chapter within this time
//event is reported to GA

function settimer(ii) {
    scrollstat[ii].timer = true; 
    setTimeout(function() {doublecheck(ii);},3000);  
}

//Handling scrolling event
$(window).scroll(function() {
    scrollpos = $(window).scrollTop();
    max = scrollpos + 300;
    min = scrollpos;
    for (index = 0; index < scrollstat.length; ++index) {
        if (scrollstat[index].checked == false &&
        scrollstat[index].timer == false &&
        scrollstat[index].offset.top > min &&
        scrollstat[index].offset.top < max) {
              settimer(index);
        }
    }
});

</script>

MAX和MIN变量是通过实验估算的。就我而言,我假定必须将章节标题滚动到屏幕顶部。

根据上述脚本,每个章节都会作为单独的页面访问报告给GA,其地址为:“ / SECTION-chapter-title /”

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我可以在其他网站上重复使用相同的Google Analytics(分析)跟踪ID

Codeigniter网站上的Google Analytics(分析)API

用于单页api的Google Analytics(分析)

跟踪用户不在网站上时发生的 Google Analytics 事件

如何使用Google Analytics(分析)跟踪AJAX网站搜索?

通过Google Analytics(分析)记录我网站上的登录用户

Google Analytics(分析)如何获取“任意时刻网站上的活跃用户数”的指标

如何使用Google Analytics(分析)跟踪用户对MFMailComposeViewController的操作?

使用Google Analytics(分析)跟踪用户链接点击

Google Analytics(分析)用户ID跟踪

跟踪用户在单页网站上看到/滚动的内容?

如何在Vue网站上正确设置Google Analytics(分析)?

使用Google Analytics(分析)追踪网站上一个网址的使用者

Google Analytics(分析)跟踪在一页结帐中退出

在同一网站上使用Google Analytics(分析)和Piwik

是否在父和子Django模板中都添加Google Analytics(分析)跟踪脚本,还是在Django网站上仅添加父模板?

使用Google Analytics(分析)iOS跟踪崩溃

使用Google Analytics(分析)跟踪片段

使用Google Analytics(分析)跟踪变量

使用Google Analytics(分析)跟踪我的下载

如何使用Google Analytics(分析)针对第三方网站创建跟踪像素?

Google Analytics(分析)iOS:它如何跟踪用户?

针对单个用户的Google Analytics(分析)事件跟踪

Google Analytics-跟踪第三方网站上的转化

如何在网站上添加多个 Google Analytics 跟踪器?(HTML,JS)

即使使用新的用户名和网站ID,也超出了Google Analytics(分析)API的限制

跟踪视图Google Analytics(分析)

Google Analytics(分析)异常跟踪

使用Google Analytics(分析),我如何跟踪查看同一页面的不同细分受众群?