多次检查用户是否已达到预期的DIV

时间:2014-05-23 15:40:49

标签: javascript jquery google-analytics

我正在尝试使用Justin Cutroni的Javascript的修改版本来跟踪和分析用户行为。例如,我想知道用户需要多长时间才能到达内容div的末尾并且(考虑到文章中的单词数量),确定用户是否刚刚扫描了该站点。我用这段代码:

// If user has hit the bottom of the content send an event
if (bottom >= $('#lorem').scrollTop() + $('#lorem').innerHeight() && !endContent) {
    currentTime = new Date();
    contentScrollEnd = currentTime.getTime();
    timeToContentEnd = Math.round((contentScrollEnd - scrollStart) / 1000);

    var palabras = document.getElementById('lorem').innerHTML.split(' ').length;

    var tiempo_estimado_lector =  Math.round(palabras / 400)*60;
    var tiempo_estimado_lector_intensivo =  Math.round(palabras / 250)*60;

    if (timeToContentEnd < tiempo_estimado_lector) {
    var tipo_lector = "Escaneador";
    } else if (timeToContentEnd < tiempo_estimado_lector_intensivo) {
        var tipo_lector = "Lector";
        } else {
        var tipo_lector = "Lector intensivo";
        }
    if (!debugMode) {
        ga('set', 'dimension5', tipo_lector); 
        ga('send', 'event', 'Reading', 'ContentBottom', pageTitle, timeToContentEnd, {'metric2' : timeToContentEnd});
    } else {
        alert('end content section ' + tipo_lector + ' ' + timeToContentEnd);
    }
    endContent = true;
}

它运行顺畅,当用户到达内容div的末尾时显示警告消息。但是,如果我尝试使用另一个div元素(例如comments部分)复制相同的内容,则会在用户开始滚动时弹出警报窗口。我刚刚复制了&amp;粘贴div内容的代码并更改变量,如:

   // If user has hit the bottom of the comment section send an event
    if (bottom >= $('#comments').scrollTop() + $('#comments').innerHeight() && !endComments) {
        currentTime = new Date();
        commentsScrollEnd = currentTime.getTime();
        timeToCommentsEnd = Math.round((commentsScrollEnd - scrollStart) / 1000);

        var palabras3 = document.getElementById('comments').innerHTML.split(' ').length;

        var tiempo_estimado_lector3 =  Math.round(palabras3 / 400)*60;
        var tiempo_estimado_lector_intensivo3 =  Math.round(palabras3 / 250)*60;

        if (timeToCommentsEnd < tiempo_estimado_lector3) {
        var tipo_lector3 = "Escaneador";
        } else if (timeToCommentsEnd < tiempo_estimado_lector_intensivo3) {
            var tipo_lector3 = "Lector";
            } else {
            var tipo_lector3 = "Lector intensivo";
            }
        if (!debugMode) {
            ga('set', 'dimension6', tipo_lector3); 
            ga('send', 'event', 'Reading', 'CommentsBottom', pageTitle, timeToCommentsEnd, {'metric3' : timeToCommentsEnd});
        } else {
            alert('end comments section ' + tipo_lector + ' ' + timeToCommentsEnd);
        }
        endComments = true;
    }  

每个网页浏览一次这个程序是否正常?这毫无意义!!

整个代码(和演示):http://agustin-suarez.com/demos/grupo-categorias/

0 个答案:

没有答案