...
|
...
|
@@ -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 |
...
|
...
|
|