Authored by 梁志锋

增加发送用户自定义信息、用户鼠标事件、记录点击a标签时鼠标位置等功能

... ... @@ -5,6 +5,7 @@ var fs = require('fs');
var exec = require('child_process').exec;
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var concat = require('gulp-concat');
... ...
This diff could not be displayed because it is too large.
{
"name": "yas-jssdk",
"version": "1.0.9",
"version": "1.0.15",
"description": "YOHO!采集系统的前端js的开发包",
"keywords": ["YOHO!", "Acquisition", "System", "JS-SDK"],
"homepage": "",
... ... @@ -19,10 +19,14 @@
"licenses": "MIT",
"spm": {
"main": "yas.js",
"dependencies": {},
"dependencies": {
"yoho.sizzle": "2.2.2-pre",
"yoho.json2": "1.0.0"
},
"devDependencies": {
"expect.js": "0.3.1",
"sinon": "1.6.0"
"sinon": "1.6.0",
"yoho.sizzle": "2.2.2-pre"
},
"buildArgs": "--include standalone"
},
... ...
... ... @@ -17,6 +17,10 @@ var ev = require('./event');
var config = require('./config');
var sizzle = require('yoho.sizzle');
require('yoho.json2');
//sdk 版本
var version = config.version;
... ... @@ -34,7 +38,7 @@ var appInfo = {
fst: 0, //firstScreenTime
// dt:document.title,//document title
sv: '', // YAS版本
ab: cookies('ab_1') || ''
ab: cookies('ab_5') || ''
};
//获取跟踪ID
... ... @@ -74,7 +78,7 @@ var browserInfo = {
var eventArray = [];
//入口方法
var _yas = function(initTime, version, tid, uid, geo) {
var _yas = function(initTime, version, tid, uid, geo, selector) {
custInfo.ak = tid;
appInfo.sv = version;
custInfo.ud = uid ? uid : '';
... ... @@ -129,6 +133,37 @@ var _yas = function(initTime, version, tid, uid, geo) {
}
/**
* 用于统计用户点击了选择器元素的序号,此方法依赖第三方库Sizzle
* 记录cookie, 待进入新页面后通过send方法将cookie中的鼠标记录发送并清空.
*
*/
var nodes = null;
if (selector) {
if (Object.prototype.toString.call(selector) === "[object String]") {
if (sizzle) {
nodes = sizzle(selector);
}
} else {
nodes = selector;
}
}
if (nodes) {
for (var index = 0, length = nodes.length; index < length; index++) {
(function(i){
ev.addEventHandler(nodes[i], 'click', function (e) {
ix = i + 1;
var pos = getMouseEventPosition(e);
cookies('_yasmp', pos.x + ',' + pos.y + ',' + e.type + ',' + (i + 1), {
path: '/',
domain: yasDomain,
expires: 365 * 200
});
});
})(index);
}
} else {
/**
* <a>标签的点击事件,适用于页面跳转的情形
* 记录cookie, 待进入新页面后通过send方法将cookie中的鼠标记录发送并清空.
*
... ... @@ -136,7 +171,7 @@ var _yas = function(initTime, version, tid, uid, geo) {
ev.addEventHandler(document, 'click', function(e) {
e = e || window.event;
var target = e.target || e.srcElement;
if(target && target.nodeName === "IMG" && target.parentNode.nodeName === "A") {
if(target && (target.nodeName === 'A' || (target.nodeName === 'IMG' && target.parentNode.nodeName === 'A'))) {
var pos = getMouseEventPosition(e);
cookies('_yasmp', pos.x + ',' + pos.y + ',' + e.type, {
path: '/',
... ... @@ -144,8 +179,9 @@ var _yas = function(initTime, version, tid, uid, geo) {
expires: 365 * 200
});
}
ix = 0;
});
}
};
... ... @@ -161,6 +197,18 @@ function send(callback) {
expires: 365 * 200
});
}
var _custjsonstr = cookies('_yascustjson');
if (_custjsonstr) {
var custjson = JSON.parse(_custjsonstr);
info = util.merge(info, custjson);
cookies('_yascustjson', null, {
path: "/",
domain: config.yasDomain,
expires: 365 * 200
});
}
var param = util.genParam(info);
callback = callback ? callback : function () {
};
... ... @@ -175,8 +223,6 @@ function send(callback) {
});
});
}
}
function getVisitorId() {
... ... @@ -204,11 +250,21 @@ function getMousePosition() {
var mp = cookies('_yasmp');
if (mp) {
var mpObject = mp.split(',');
if (mpObject.length === 3) {
return {
x: mpObject[0],
y: mpObject[1],
et: mpObject[2]
};
} else if (mpObject.length === 4) {
return {
x: mpObject[0],
y: mpObject[1],
et: mpObject[2],
ix: mpObject[3]
};
}
}
return null;
}
... ... @@ -269,20 +325,59 @@ function _addEv2Cookies(trackType, input, action, label, value) {
evTimes++;
}
// 发送用户页面事件,不记cookie, 适用于页面不跳转的情形, 此方法提供给用户调用
_yas.sendEvent = function(e) {
/**
* 发送用户鼠标事件的位置, 此方法提供给用户调用, 本方法不对参数合法性进行检查, 调用者自己保证。
* @param json 用户订制信息, 必选参数,采用json格式
* @param flag 用户事件执行后, 页面是否停留当前页, 是可选参数
* true表示停留,false表示跳转, 默认值是false
* 取值是false时, 记录cookie, 待进入新页面后通过send方法将cookie中的事件记录发送并清空。
*/
_yas.sendMouseEvent = function(e, flag) {
e = e || window.event;
var pos = getMouseEventPosition(e);
if (!flag) {
cookies('_yasmp', pos.x + ',' + pos.y + ',' + e.type, {
path: '/',
domain: yasDomain,
expires: 365 * 200
});
} else {
var mp = {
x: pos.x,
y: pos.y,
et: e.type,
et: e.type
};
var info = util.merge(appInfo, custInfo);
info = util.merge(info, browserInfo);
info = util.merge(info, mp);
var param = util.genParam(info);
cross.imgSend(param, function () {});
}
};
/**
* 发送用户订制信息, 此方法提供给用户调用, 本方法不对参数合法性进行检查, 调用者自己保证。sendCustomInfo
* @param json 用户订制信息, 必选参数,采用json格式
* @param flag 用户事件执行后, 页面是否停留当前页, 是可选参数, 默认是页面跳转
* true表示停留,false表示跳转, 默认值是false
* 取值是false时, 记录cookie, 待进入新页面后通过send方法将cookie中的事件记录发送并清空。
*/
_yas.sendCustomInfo = function(json, flag) {
if (!flag) {
var string = JSON.stringify(json);
cookies('_yascustjson', string, {
path: '/',
domain: yasDomain,
expires: 365 * 200
});
} else {
var info = util.merge(appInfo, custInfo);
info = util.merge(info, browserInfo);
util.merge(info, mp);
info = util.merge(info, json);
var param = util.genParam(info);
cross.imgSend(param, function () {});
}
};
module.exports = _yas;
\ No newline at end of file
... ...
... ... @@ -21,7 +21,7 @@
a.src=j;
m.parentNode.insertBefore(a,m);
}
)(window,document,'script','/dist/yas-jssdk/1.0.13/yas.js&'+Math.random(),'_yas');
)(window,document,'script','/dist/yas-jssdk/1.0.15/yas.js&'+Math.random(),'_yas');
_yas(1*new Date(),'1.0','ds6das2kkj','21323231','geo');
... ...
<!DOCTYPE HTML>
<html lang="en">
<head>
<head>
<meta charset="UTF-8">
<title>yas-jssdk - Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="generator" content="nico 0.5.1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script type="text/javascript" src="../yas.js"></script>
<script type="text/javascript">
seajs.use('yas',function(_yas){
_yas(1*new Date(),'1.0','ds6das2kkj','21323231','geo');
});
</script>
<script>
(
function(w,d,s,j,f)
{
w['YohoAcquisitionObject'] = f;
w[f] = function()
{
w[f].p=arguments;
};
var a=d.createElement(s);
var m=d.getElementsByTagName(s)[0];
a.async=1;
a.src=j;
m.parentNode.insertBefore(a,m);
}
)(window,document,'script','/dist/yas-jssdk/1.0.15/yas-debug.js','_yas');
_yas(1*new Date(),'1.0','ds6das2kkj','21323231','geo', '.test >a >img');
window.onload = function(){
alert('haha!');
var button = document.getElementById('button');
button.onclick = function(e){
_yas.sendMouseEvent(e);
}
}
</script>
</head>
<body>
<body style="height:2000px; width:800px; scroll:auto">
<div class="test">
<a href="test2.html">
<img src="http://img11.static.yhbimg.com/yhb-img01/2015/09/12/06/013a80e1affcac788863ef4325b0708e82.jpg?imageView/2/w/640/h/240">
</a>
</div>
<p><button id="button">触发记录</button>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -21,27 +21,30 @@
a.src=j;
m.parentNode.insertBefore(a,m);
}
)(window,document,'script','../dist/yas-jssdk/1.0.13/yas-debug.js','_yas');
)(window,document,'script','/dist/yas-jssdk/1.0.15/yas-debug.js','_yas');
_yas(1*new Date(),'1.0','ds6das2kkj','21323231','geo');
_yas(1*new Date(),'1.0','ds6das2kkj','21323231','geo', '.test >a >img');
window.onload = function(){
alert('haha!');
var button = document.getElementById('button');
button.onclick = function(e){
_yas.sendEvent(e);
_yas.sendMouseEvent(e);
}
}
</script>
</head>
<body style="height:2000px; width:800px; scroll:auto">
<a href="http://www.baidu.com">
<div class="test">
<a href="test2.html">
<img src="http://7xlrzp.com1.z0.glb.clouddn.com/IMG_0118.JPG?format/webp">
</a>
<a href="http://www.baidu.com">
<img src="http://7xlrzp.com1.z0.glb.clouddn.com/IMG_0117.JPG?format/webp">
<a href="test.html">
<img src="http://7xlrzp.com1.z0.glb.clouddn.com/IMG_0118.JPG?format/webp">
</a>
</div>
<p><button id="button">触发记录</button>
</body>
</html>
\ No newline at end of file
... ...