追踪 Lander 的上的点击事件、滚动操作事件、以及访客存活。

感谢 @WKKKK 提供代码

Lander 配合 Afilter Tracker 的事件追踪可以提供很多功能,有很多玩法。

下面贴出来的代码可以追踪 Lander 的点击事件、滚动操作事件、以及访客存活。

<script>
var nub=0;
var nub1=0;
var nub2=0;
var nub3=0;
//点击事件,回传并跳转
function clickEvent(){
    //alert("发送点击成功!")
    $.ajax({
                type: "POST",
                url: "https://afilter.xyz/p/events",
                data: {"et":1},
                xhrFields: {withCredentials: true},
                crossDomain: true,
            });
            window.location.href="https://afilter.xyz/click";
    }
//用户在页面完成下拉与上拉的动作,回传
function scrollEvent() {

    window.onscroll = function(e){
        scrollFunc();
        if(scrollDirection == 'down'){
            //页面向下滚动要做的事情
            nub1=nub1+1;
        }
        else if(scrollDirection == 'up'){
            //页面向上滚动要做的事情
            nub2=nub2+1;
        }
        if (nub1>3&&nub2>3&&nub3==0){
            //alert("追踪滑动成功!")
        $.ajax({
                type: "POST",
                url: "https://afilter.xyz/p/events",
                data: {"et":2},
                xhrFields: {withCredentials: true},
                crossDomain: true,
            });
        nub3=1;
        }
    }
}

var scrollAction = {x: 'undefined', y: 'undefined'}, scrollDirection;
function scrollFunc() {
    if (typeof scrollAction.x == 'undefined') {
        scrollAction.x = window.pageXOffset;
        scrollAction.y = window.pageYOffset;
    }
    var diffX = scrollAction.x - window.pageXOffset;
    var diffY = scrollAction.y - window.pageYOffset;
    if (diffX < 0) {
        // Scroll right
        scrollDirection = 'right';
    } else if (diffX > 0) {
        // Scroll left
        scrollDirection = 'left';
    } else if (diffY < 0) { 
        // Scroll down
        scrollDirection = 'down';
    } else if (diffY > 0) {
        // Scroll up
        scrollDirection = 'up';
    } else {
        // First scroll event
    }
    scrollAction.x = window.pageXOffset;
    scrollAction.y = window.pageYOffset;
}
//用户停留时间10s
function staytime10(){
    //alert("10s")
        $.ajax({
                type: "POST",
                url: "https://afilter.xyz/p/events",
                data: {"et":3},
                xhrFields: {withCredentials: true},
                crossDomain: true,
            });
    }
    //用户停留时间30s
function staytime30(){
        //alert("30s")
        $.ajax({
                type: "POST",
                url: "https://afilter.xyz/p/events",
                data: {"et":4},
                xhrFields: {withCredentials: true},
                crossDomain: true,
            });
    }
    //用户停留时间60s
function staytime60(){
        //alert("60s")
        $.ajax({
                type: "POST",
                url: "https://afilter.xyz/p/events",
                data: {"et":5},
                xhrFields: {withCredentials: true},
                crossDomain: true,
            });
    }
    //用户停留时间120s
function staytime120(){
        //alert("120s")
        $.ajax({
                type: "POST",
                url: "https://afilter.xyz/p/events",
                data: {"et":6},
                xhrFields: {withCredentials: true},
                crossDomain: true,
            });
    }
window.onload=function(){
    scrollEvent();
    setTimeout(staytime10,10000);
    setTimeout(staytime30,30000);
    setTimeout(staytime60,60000);
    setTimeout(staytime120,120000);
    }
</script>

请将 afilter.xyz 更改为您自己在 Afilter Tracker 绑定的域名