使用Google Analytics跟踪滑动 [英] Track swipes with Google Analytics

查看:120
本文介绍了使用Google Analytics跟踪滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的手机页面上有一个滑动功能,我想用touchstart,touchend和touchmove跟踪设备上的滑动功能,而不会影响滚动。



<这是我的代码。

  jQuery('。first-frame')。bind('touchmove',function(event){
_gaq .push(['_ trackEvent','Landing-Page','Swipe-Toggle-Color','0259_2190']);
});


解决方案

如果可以只监视 swipeleft

否则,您可以在滚动事件上设置全局变量,例如0.2秒后重置。然后让 touchmove 事件检查是否设置了该变量,如果是,则不要触发Google Analytics。

  window.is_scrolling = false; //全局变量
window.timeout_id = 0;

window.onscroll = function(){
window.is_scrolling = true;
clearTimeout(window.timeout_id);
window.timeout_id = setTimeout(function(){
window.is_scrolling = false;
},200); //毫秒
};
$ b $ j('。first-frame')。bind('touchmove',function(event){
if(!window.is_scrolling)
_gaq.push(['' _trackEvent','Landing-Page','Swipe-Toggle-Color','0259_2190']);
});


I have a swipe functionality on my mobile page, and I want to used touchstart, touchend, and touchmove to track the swipe functionality across the device without affecting the scrolling.

Here is my code.

jQuery('.first-frame').bind('touchmove', function(event) {
 _gaq.push(['_trackEvent', 'Landing-Page', 'Swipe-Toggle-Color', '0259_2190']);
});

解决方案

If it's possible to only monitor the swipeleft and swiperight events in jQuery Mobile instead, do so.

Otherwise, you can set a global variable on the scroll event that resets after, say, 0.2 seconds. Then have the touchmove event check if that variable is set, and if it is, don't trigger Google Analytics.

window.is_scrolling = false; // global variable
window.timeout_id = 0;

window.onscroll = function() {
    window.is_scrolling = true;
    clearTimeout(window.timeout_id);
    window.timeout_id = setTimeout(function() { 
        window.is_scrolling = false; 
    }, 200); // milliseconds
};

jQuery('.first-frame').bind('touchmove', function(event) {
    if (!window.is_scrolling) 
       _gaq.push(['_trackEvent', 'Landing-Page', 'Swipe-Toggle-Color', '0259_2190']);
});

这篇关于使用Google Analytics跟踪滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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