Authored by 沈志敏

添加ab测试上报事件

{
"name": "yoho-js-sdk",
"version": "1.1.2",
"version": "1.1.3",
"description": "YOHO!前端js的功能封装包,主要用于在活动页面中,对主要功能的封装。",
"keywords": [
"YOHO!",
... ...
... ... @@ -3,6 +3,7 @@ import jsonp from './jsonp';
import utils from './utils';
import cookies from './cookies';
let abTestFlag = false; // ab测试
let _replaceData = function(el, cond, data, wh) {
if (!data || !data.default_images) {
return;
... ... @@ -50,25 +51,24 @@ let _replaceData = function(el, cond, data, wh) {
};
let _jsonp = function(el, param, cond){
let cloneitem = el.attr('cloneitem');
let goods = el.find('.feature-product-info');
if (!goods.length) {
return;
}
if (cond.abtest) {
// ab测试
if (param.uid && Number(param.uid) % 2 === 0) { // cover覆盖mkt_code
utils.sParamByIframe('cover=1&mkt_code=100000000000195&expires=' + (7 * 24 * 60 * 60 * 1000)); // 默认的值
goods.removeClass('novisible');
// ab测试,访客 和 >=512的uid 显示默认推荐
if (!param.uid || (Number(param.uid) % 1024 >= 512)) {
if (cloneitem) {
$(goods[0]).remove();
} else {
goods.removeClass('novisible');
}
return;
} else if (param.uid && Number(param.uid) % 2 === 1) {
utils.sParamByIframe('cover=1&mkt_code=100000000000193&expires=' + (7 * 24 * 60 * 60 * 1000)); // 个性化,动态接口数据
} else {
utils.sParamByIframe('cover=1&mkt_code=100000000000197&expires=' + (7 * 24 * 60 * 60 * 1000)); // 访客接口数据
}
}
let cloneitem = el.attr('cloneitem');
let imgwh = el.find('.imgwh').val() || ''; // 获取图片宽x高
imgwh = imgwh.split('x') || [];
... ... @@ -123,12 +123,64 @@ let _jsonp = function(el, param, cond){
});
};
let _abTest = function(uid) {
let mkt_code;
if (uid) {
if (Number(uid) % 1024 >= 512) {
mkt_code = 100000000000195; // 默认的值
} else {
mkt_code = 100000000000193; // 个性化,动态接口数据
}
} else {
mkt_code = 100000000000197; // 访客接口数据
}
// cover覆盖mkt_code
utils.sParamByIframe('cover=1&mkt_code=' + mkt_code +'&expires=' + (7 * 24 * 60 * 60 * 1000));
// 上报曝光事件
let actionUrl = [];
$('a').each(function(){
actionUrl.push($(this).attr('href'));
});
if (window._yas && window._yas.sendAppLogs) {
window._yas.sendAppLogs({
appop: 'YB_H5_PAGE_AB_OPEN_L',
param: JSON.stringify({
C_ID: utils.queryString().yh_channel || 1,
PAGE_URL: window.originUrl,
PAGE_NAME: decodeURI(window.qs.title || document.title),
ACTION_URL: actionUrl,
CROWD_CODE: mkt_code
})
}, true);
$('a').click(function() {
window._yas.sendAppLogs({
appop: 'YB_H5_PAGE_AB_FLR_C',
param: JSON.stringify({
C_ID: utils.queryString().yh_channel || 1,
PAGE_URL: window.originUrl,
PAGE_NAME: decodeURI(window.qs.title || document.title),
F_URL: $(this).attr('href'),
CROWD_CODE: mkt_code
})
}, true);
});
}
};
let _getProduct = function(param) {
$('.product-source').each(function(i, el){
el = $(el);
let yh_channel = utils.queryString().yh_channel,
cond = JSON.parse(el.attr('condition') || '{}');
if (cond.abtest) {
abTestFlag = true;
}
if (yh_channel) {
cond.yh_channel = yh_channel;
}
... ... @@ -141,6 +193,8 @@ let _getProduct = function(param) {
_jsonp(el, param, cond);
}
});
abTestFlag && _abTest(param.uid);
};
export default {
... ...