基于jQuery或Zepto实现实时监控用户浏览信息
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了基于jQuery或Zepto实现实时监控用户浏览信息,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3451字,纯文字阅读大概需要5分钟。
内容图文
对于一些大型公司,想要有一些监控用户行为的分析,怎么办?
比如一个场景,A公司想要监控用户浏览当前屏幕有哪些数据怎么办?
那么就用到本文所提的监控解决方案了:
1.首先要监控用户到底在该屏停留了多久;
2.基于1确定用户是停留在了本页面而没有滑动手机屏幕;
3.在用户未达到条件后的callback机制。
基于以上的问题,我们可以想到时间分片
1 /* This is a expose advertisements component. 2 * Base on some class libraries that has dom selector such as jQuery or Zepto. 3 * The bind dom must be a block element. 4 * use as $(‘.class‘).exposure(settings); 5 * The bottom expose proportion use ($(window).height() + $(window).scrollTop() - $(‘.class‘).eq(index).offset().top)/$(‘.class‘).eq(index).height() 6 * The top expose proportion use (1 - ($(window).scrollTop() - $(‘.class‘).eq(index).offset().top)/$(‘.class‘).eq(index).height()) 7 * settings: object 8 * { 9 * ‘exposeSecond‘: 2 // 2 seconds for advertisement to expose 10 * ‘timePeriod‘: 100 // 100 Millisecond for every time period 11 * ‘sendFunction‘: function(){} // callback for each expose time 12 * } 13 */ 14 (function($, window){ 15 $.fn.exposure= function(settings) { 16var $this = $(this), el = {}, _winScrollTop = _winScrollTop = $(window).scrollTop(), _winHeight = $(window).height(), watcher = null, sendQueue = [], checkOldTop = checkNewTop = 0, timePeriod = settings.timePeriod || 100, topThis = this, staySecond = settings.exposeSecond || 4, nowTime = 0, sendedQueue = [], turnFlag = true, proportion = 0.8; 17var stayTime = timePeriod * 10 * staySecond; 18var _bindElement = function() { 19 el = { 20 $ads: $this21 }; 22 }, 23 _bindAction = function() { 24 $(window).on(‘scroll.ad‘, function(eve){ 25 _winScrollTop = $(window).scrollTop(); 26 _winHeight = $(window).height(); 27 _checkAdSection(); 28 }); 29 }, 30 _checkAdSection = function() { 31 sendQueue = []; 32 turnFlag = true; 33var _checkNewTop = 0; 34 el.$ads.each(function() { 35var $self = $(this); 36var _offsetTop = $self.offset().top; 37var _eleHeight = $self.height(); 38if (_offsetTop <= _winScrollTop && _offsetTop + _eleHeight > _winScrollTop && (_offsetTop + _eleHeight * (1 - proportion)) >= _winScrollTop) { 39 sendQueue.push($self); 40 _checkNewTop = _checkNewTop ? _checkNewTop : _offsetTop; 41 } 4243if (_offsetTop > _winScrollTop && _offsetTop <= (_winHeight + _winScrollTop) && (_offsetTop + _eleHeight * proportion) <= (_winHeight + _winScrollTop)) { 44 _checkNewTop = _checkNewTop ? _checkNewTop : _offsetTop; 45 sendQueue.push($self); 46 } elseif (_offsetTop > (_winHeight + _winScrollTop)){ 47returnfalse; 48 } 49 }); 50 checkNewTop = _checkNewTop; 51 }, 52 _startWatcher = function() { 53if (watcher) { 54return; 55 } 5657 watcher = setInterval(function(){ 58if (!turnFlag) { 59returntrue; 60 } 6162if (nowTime >= stayTime) { 63 turnFlag = false; 64 nowTime = 0; 65 _sendQueueHandler($.extend({}, sendQueue)); 66returntrue; 67 } 6869if (checkOldTop == checkNewTop) { 70 nowTime += timePeriod; 71 } else { 72 checkOldTop = checkNewTop; 73 nowTime = 0; 74 } 75 }, timePeriod); 76 }, 77 _sendQueueHandler = function(sendQueueArray) { 78 settings.sendFunction(sendQueueArray); 79 }, 80 _init = function() { 81 _bindElement(); 82 _bindAction(); 83 setTimeout(function() { 84 _winHeight = $(window).height(); 85 _checkAdSection(); 86 }, stayTime); 8788 _startWatcher(); 89 }; 90 _init(); 91 } 92 })($, window);
$(‘.expose-node‘).exposure({
exposeSecond: 2,//曝光时间2s
sendFunction:function(nodes){//do what you want}//两秒到了回传的notes,自己处理具体要干什么
});
原文:http://www.cnblogs.com/houMing/p/6590913.html
内容总结
以上是互联网集市为您收集整理的基于jQuery或Zepto实现实时监控用户浏览信息全部内容,希望文章能够帮你解决基于jQuery或Zepto实现实时监控用户浏览信息所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。