在页头部加载一个JS即track_refs.js,此js的作用为记录url中某些参数,用记入cookie 在一定的情况下,记入数据库,如下订单等
var set_cookie = false, cookie = $.cookie('_refs'), refs = (cookie == null) ? ['','','',''] : cookie.split("~~"), r_1 = queryString('from');
先判断COOKIE中有没有过记录,如果没有设为空,有的话重新分析,并存至r_1中。
function queryString( key )
{
if ( !defined( gQS[ key ] ) )
{
var reQS = new RegExp( "[?&]" + key + "=([^&$]*)", "i" );
var offset = location.search.search( reQS );
gQS[ key ] = ( offset >= 0 ) ? decodeURIComponent(RegExp.$1) : null;
}
return gQS[ key ];
}
EDM中邮件的存入,将url中必要信息存入cookie中
var r_0, reHost = new RegExp("http://([a-z0-9\-\.]+?\.)?([a-z0-9\-]+)\.([a-z]{2,4})/([^\/]+)?", "i"), match = reHost.exec(document.referrer);
if (!isEmpty(document.referrer) && $.isArray(match) && match.lenght > 0) {
if (match[2] != 'persy') {
r_0 = match[1] + match[2] + match[3];
} else if (match[2] == 'persy' && defined(match[4]) && match[4] == 'feature') {
r_0 = match[2] + match[3] + '/' + match[4];
} else {
r_0 = null;
}
if (!isEmpty(r_0)) {
refs[0] = r_0;
}
} else {
refs[0] = '(empty)';
}
在上文中$.cookie的函数的作用为:
// $.cookie plugin
$.cookie = function(name, value, options) {//name为cookie的键,value为值,options是设置cookie的参数json格式。
当value类型非undefined时options = options || {}; 让设置参数为空json 如果value为null时 让value为空并options = $.extend({}, options); options.expires = -1;
时间设置
判断options.expires是否有值 或为为数据 或.toUTCString 然date = new Date();date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toUTCString();
options.path --- options.domain --- options.secure
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');