使用Google Analytics跟踪滑动 [英] Track swipes with Google Analytics
问题描述
我的手机页面上有一个滑动功能,我想用touchstart,touchend和touchmove跟踪设备上的滑动功能,而不会影响滚动。
<这是我的代码。
jQuery('。first-frame')。bind('touchmove',function(event){
_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.
If it's possible to only monitor the Otherwise, you can set a global variable on the
这篇关于使用Google Analytics跟踪滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 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']);
});
jQuery('.first-frame').bind('touchmove', function(event) {
_gaq.push(['_trackEvent', 'Landing-Page', 'Swipe-Toggle-Color', '0259_2190']);
});
swipeleft
and swiperight
events in jQuery Mobile instead, do so.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']);
});