(function (w) {
var HOST_NAME_PRO = "news.7654.com"; // 正式域名
var MINI_QID = "kuaiya"; // 正式域名
var MINI_PRO = "kuaizip";
var ds_fun_c = {
open_ssp: true, // 是否开启ssp(dsp)
};
w.ds_config = {
project_type: "weather", // 项目 weather
pub_config_key: "proConfig", // index中的公共配置键名
project: "kuaizip", // 直客上报项目名
miniLeft1: {
id: 4,
ad_pos: MINI_QID + "_minileft_1",
cname: "miniLeft1",
ucn: "uploadConfig11", // 上报参数全局对象名
muc: "_click_gg11", // miniLeft1上报位置class
pt: "mininewsplus_5", // dsp广告位置popType值
},
miniLeft2: {
id: 5,
ad_pos: MINI_QID + "_minileft_2",
cname: "miniLeft2",
ucn: "uploadConfig12", // 上报参数全局对象名
muc: "_click_gg12", // miniLeft2上报位置class
pt: "mininewsplus_4", // dsp广告位置popType值
},
miniRight1: {
id: 6,
target: ".right1",
ad_pos: MINI_QID + "_miniright_1",
cname: "miniRight1",
ucn: "uploadConfig1", // 上报参数全局对象名
muc: "_click_gg1", // miniRight3上报位置class
pt: "mininewsplus_3", // dsp广告位置popType值
},
miniRight2: {
id: 7,
target: ".right2",
ad_pos: MINI_QID + "_miniright_2",
cname: "miniRight2",
ucn: "uploadConfig2", // 上报参数全局对象名
muc: "_click_gg2", // miniRight3上报位置class
pt: "mininewsplus_2", // dsp广告位置popType值
},
miniRight3: {
id: 8,
target: ".right3",
ad_pos: MINI_QID + "_miniright_3",
cname: "miniRight3",
ucn: "uploadConfig3", // 上报参数全局对象名
muc: "_click_gg3", // miniRight3上报位置class
pt: "mininewsplus_1", // dsp广告位置popType值
}
};
/* ============================= ssp and dsp ================================= */
function SspAndDsp() {
}
SspAndDsp.prototype = {
initSspL: function () {
if (!ds_fun_c.open_ssp) {
return w.ad360.statusRender360Left(["null", "null"]);
}
var _this = this;
// 左侧信息流
var targetTab = ".content .scroll_con." + w[ds_config.pub_config_key].curTabBtn.attr("date-type");
this.getSspData(function (res) {
var ssp_1;
var ssp_2;
var data1 = res.data[ds_config.miniLeft1.ad_pos];
var data2 = res.data[ds_config.miniLeft2.ad_pos];
// data2.script.length = 0;
if (data1.script.length !== 0 && data2.script.length !== 0) {//第一张ssp/dsp,第二张ssp/dsp
// 需要添加dsp
ssp_1 = new MPromise(function (resolve, reject) {
_this.renderSspAndDsp(data1, $(targetTab + " .list_item").eq(0), ds_config.miniLeft1, function (type) {
resolve(type);
});
});
ssp_2 = new MPromise(function (resolve, reject) {
_this.renderSspAndDsp(data2, $(targetTab + " .list_item").eq(1), ds_config.miniLeft2, function (type) {
resolve(type);
});
});
MPromise.all([ssp_1, ssp_2])
.then(function (result) {
w.ad360.statusRender360Left(result);
});
} else if (data1.script.length === 0 && data2.script.length !== 0) {//第一张无,第二张ssp/dsp
_this.renderSspAndDsp(data2, $(targetTab + " .list_item").eq(1), ds_config.miniLeft2, function (type) {
w.ad360.statusRender360Left(["null", type]);
});
} else if (data1.script.length !== 0 && data2.script.length === 0) {//第一张ssp/dsp,第二张无
_this.renderSspAndDsp(data1, $(targetTab + " .list_item").eq(0), ds_config.miniLeft1, function (type) {
w.ad360.statusRender360Left([type, "null"]);
});
} else if (data1.script.length === 0 && data2.script.length === 0) {//第一张无,第二张无
w.ad360.statusRender360Left(["null", "null"]);
}
}, 2, "left");
},
initSspR: function () {
if (!ds_fun_c.open_ssp) {
w.ad360.renderRight360(["null", 'null']);
w.ad360.renderRight360(["null"], "r3");
return;
}
var _this = this;
// 右侧
this.getSspData(function (res) {
if ($.isEmptyObject(res)) {
w.ad360.renderRight360(["null", 'null']);
} else {
var data1 = res.data[ds_config.miniRight1.ad_pos];
var data2 = res.data[ds_config.miniRight2.ad_pos];
_this.rightTop(data1, data2);
}
}, 2);
// 右下
this.getSspData(function (res) {
var datas;
if ($.isEmptyObject(res) || res.data[ds_config.miniRight3.ad_pos].script.length === 0) {
//ssp有数据并且为空
w.ad360.renderRight360(["null"], "r3");
} else {
datas = res.data[ds_config.miniRight3.ad_pos];
_this.renderSspAndDsp(datas, $(ds_config.miniRight3.target), ds_config.miniRight3, function (type) {
w.ad360.renderRight360([type], "r3");
});
$('.today_news .hot_news').hide();
}
}, 1);
},
/**
* 右上
* @param data1
* @param data2
* @returns {boolean}
*/
rightTop: function (data1, data2) {
var _this = this;
if (data1.script.length !== 0 && data1.script[0].idea_type == 14 && ds_config.project_type !== "weather") { //右上大图
$(".top_ssp").show();
$(".showcase").hide();
this.renderSspAndDsp(data1, $('.top_ssp' + ds_config.miniRight1.target), ds_config.miniRight1, function () {
});
return false;
} else if (data1.script.length !== 0 && data2.script.length !== 0 && (data1.script[0].idea_type != 14 || ds_config.project_type === "weather")) {
// 右1 右2 dsp
var dspP_1 = new MPromise(function (resolve, reject) {
_this.renderSspAndDsp(data1, $(ds_config.miniRight1.target), ds_config.miniRight1, function (dataType) {
resolve(dataType);
});
});
var dspP_2 = new MPromise(function (resolve, reject) {
_this.renderSspAndDsp(data2, $(ds_config.miniRight2.target), ds_config.miniRight2, function (dataType) {
resolve(dataType);
});
});
MPromise.all([dspP_1, dspP_2])
.then(function (result) {
w.ad360.renderRight360(result);
});
} else if (data1.script.length === 0 && data2.script.length !== 0) {
// 右1 ssp, 右2 dsp
_this.renderSspAndDsp(data2, $(ds_config.miniRight2.target), ds_config.miniRight2, function (type) {
w.ad360.renderRight360(["null", type]);
});
} else if (data1.script.length !== 0 && data2.script.length === 0 && (data1.script[0].idea_type != 14 || ds_config.project_type === "weather")) {
// 右1 ssp, 右2 dsp
_this.renderSspAndDsp(data1, $(ds_config.miniRight1.target), ds_config.miniRight1, function (type) {
w.ad360.renderRight360([type, "null"]);
});
} else if (data1.script.length === 0 && data2.script.length === 0) {
w.ad360.renderRight360(["null", 'null']);
}
},
/**
* 获取ssp数据
* @param callback
* @param rightNum 资源位数 1||2 默认1
* @param position 资源位置 left | right 默认right
*/
getSspData: function (callback, rightNum, position) {
var url;
var ad_pos;
rightNum = rightNum || 1;
position = position || "right";
switch (position + rightNum) {
case 'left2':
ad_pos = ds_config.miniLeft1.ad_pos + ',' + ds_config.miniLeft2.ad_pos;
break;
case 'right2':
ad_pos = ds_config.miniRight1.ad_pos + ',' + ds_config.miniRight2.ad_pos;
break;
case 'right1':
ad_pos = ds_config.miniRight3.ad_pos;
break;
}
url = (location.hostname === HOST_NAME_PRO ? 'http://ssp.7654.com/ssp/ads?qid=' : 'http://test-ssp.7654.com/ssp/ads?qid=') + MINI_PRO + '&ad=' + ad_pos;
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
success: function (res) {
var obj = {};
if ($.isEmptyObject(res.data)) res = obj;
callback && callback(res);
},
error: function () {
var data = {};
callback(data)
}
})
},
/**
* 渲染ssp或dsp
* @param data
* @param target
* @param ad_pos
* @param status_cb 数据类型的回调
*/
renderSspAndDsp: function (data, target, ad_pos, status_cb) {
var _this = this;
var domData = data.script || [];
var dspConfig;
var zmDsp;
var params;
var url;
if (!domData[0].content) {
_this.renderSspAd(target, data, ad_pos, 'ssp', domData[0].mini_reader == '1');
// ssp-直客上报
_this.upConfigParams(data, ad_pos);
_this.uploadZhike(window[ad_pos.ucn]);
status_cb && status_cb('ssp')
} else {
dspConfig = JSON.parse(data.script[0].content);
zmDsp = {
requestId: 1e18 * Math.random(),
slot: {
// uid: Common.getCookie(), // 删除
proj: Common.GetQueryString('project') || (location.hostname === "localhost" ? 'kuaizip':"default"),
mixData: Common.GetQueryString('data') || (location.hostname === "localhost" ? 'cnJrk4xEHwebcpWgjC2ggGKY1P7mkFumzBDQkaEiLchtwM3g7/EQWJVXUkpjuwcRH46LONeC09JMK0gMkc5J5nEeMYh4uj3y/pXLYmwKSZp+ptHX4R7CzoJDG9EheW/wrHp/a7xrp40jZWuM7acKsRzByeuSkg==' : 'default'),
groupid: dspConfig.groupid || 2, // 删除
popType: ad_pos.pt || 'mininewsplus_1', // 大数据 mininewsplus_1~5
}
};
params = encodeURI(JSON.stringify((zmDsp)));
url = dspConfig.url + $.base64.encode(params);
_this.upConfigParams(data, ad_pos);
window[ad_pos.ucn].act = "request";
window[ad_pos.ucn].ad_type = "dsp_zm";
_this.dspUpload(window[ad_pos.ucn]);
$.ajax({
type: "get",
url: url,
dataType: "json",
success: function (obj) {
var ads;
// obj.code = ads.imageType==12?11: obj.code;
// obj.code = ads.imageType==11?10: obj.code;
if (obj.code === 0) {
ads = obj.result.ads[0];
// console.log(dspConfig.groupid,ad_pos.id,ads.imageType);
if (dspConfig.groupid != ad_pos.id) return;
// 单图
var readStatus = ads.readStatus || '';
_this.renderSspAd(target, ads, ad_pos, 'dsp', readStatus == '1');
// ssp + dsp上报
data.script[0].plan_id = ads.planId;
data.script[0].ad_type = _this.handleAdType(domData[0], ads.adType);
_this.upConfigParams(data, ad_pos);
_this.uploadZhike(window[ad_pos.ucn]);
window[ad_pos.ucn].dspData = JSON.stringify(ads);
// window[ad_pos.ucn].act = "request";
// _this.dspUpload(window[ad_pos.ucn]);
window[ad_pos.ucn].act = "show";
_this.dspUpload(window[ad_pos.ucn]);
status_cb && status_cb('dsp');
// if (readStatus == '1') {
// // swpiw 1用阅读器打开
// $('head').append('');
// } else {
// $('head').append('');
// }
} else {
_this.upConfigParams(data, ad_pos);
window[ad_pos.ucn].act = "null";
window[ad_pos.ucn].ad_type = "dsp_zm";
_this.dspUpload(window[ad_pos.ucn]);
status_cb && status_cb('null');
}
},
error: function (err) {
_this.upConfigParams(data, ad_pos);
window[ad_pos.ucn].act = "error";
window[ad_pos.ucn].ad_type = "dsp_zm";
_this.dspUpload(window[ad_pos.ucn]);
status_cb && status_cb('null');
}
});
}
},
/**
* 设置ssp/dsp上传的公共参数
* @param data
* @param ad_pos
*/
upConfigParams: function (data, ad_pos) {
var param = data.script[0] || {};
window[ad_pos.ucn] = {
act: 'show',
ad_id: data.ad_id,
ad_pos: ad_pos.ad_pos,
strategy_id: param.strategy_id,
idea_id: param.idea_id,
plan_id: param.plan_id,
ad_type: param.ad_type,
product_category: data.script[0].product_category
};
},
/**
* 在目标位置插入ssp广告dom(左侧信息流)
* @param target 目标元素
* @param data ssp广告数据,即res.data[key]
* @param adType 广告类型 ssp | dsp
* @param hasMiniReader 是否有mini阅读器
* @param ad_pos dsp广告位置信息
*/
renderSspAd: function (target, data, ad_pos, adType, hasMiniReader) { // 需添加右侧模板
var value1;
value1 = JSON.parse(JSON.stringify(adType === "ssp" ? data.script[0].idea : data));
value1.adType = adType || 'ssp';
value1.aUrl = adType === "ssp" ? value1.landing_page : value1.openUrl;
value1.main_img = adType === "ssp" ? value1.main_img : value1.imageUrl;
value1.hasMiniReader = hasMiniReader;
if (target.hasClass("ssp") || target.hasClass("dsp")) {
target.html(w.adTmps.getSspDsp(value1, ad_pos, data));
} else {
// target.replaceWith(getAdTemp(value1,ad_pos,data,true));
target.before(w.adTmps.getSspDsp(value1, ad_pos, data, true));
}
},
/**
* dsp ssp 上报的ad_type处理
* @param adData
* @param adType
* @returns {string}
*/
handleAdType: function (adData, adType) {
var res = '';
var type = adData.type;
var ad_type = adData.ad_type;
if (type == 3 && ad_type == 2) {
res = "dsp_zm";
} else if (type == 2 && ad_type == 1) {
// res = "dianshang";
} else {
res = adType;
}
return res;
},
/**
* ssp 直客上报
* @param uploadAction
*/
uploadZhike: function (uploadAction) {
var params = {
project: ds_config.project || 'kuaizip',
data: Common.GetQueryString('data') || 'default',
os: Common.getSystem() || 'default',
browser: Common.getBrowser() || 'default',
act: uploadAction.act || 'default',
ad_id: uploadAction.ad_id || '2299669',
ad_pos: uploadAction.ad_pos || 'kuaiya_miniright_3',
ad_time: new Date().getTime() || 'default',
ad_type: uploadAction.ad_type || 'zhike',
strategy_id: uploadAction.strategy_id || '918',
idea_id: uploadAction.idea_id || '80',
plan_id: uploadAction.plan_id || '50',
product_category: uploadAction.product_category || 'undefined'
};
var url = "http://sspreport.7654.com/ssp/user_click?code=" + params.project + encodeURI('\t') + params.data + encodeURI('\t') + params.os + encodeURI('\t') + params.browser + encodeURI('\t') + params.act + encodeURI('\t') + params.ad_id + encodeURI('\t') + params.ad_pos + encodeURI('\t') + params.ad_time + encodeURI('\t') + params.ad_type + encodeURI('\t') + params.strategy_id + encodeURI('\t') + params.idea_id + encodeURI('\t') + params.plan_id + encodeURI('\t') + params.product_category;
$.getJSON(url).done(function (data) {
});
},
/**
* dsp 上报
* @param uploadAction 上报参数
*/
dspUpload: function (uploadAction) {
var param_dsp;
param_dsp = {
project: Common.GetQueryString('project') || 'default',
data: Common.GetQueryString('data') || 'default',
os: Common.getSystem() || 'default',
browser: Common.getBrowser() || 'default',
act: uploadAction.act || 'default',
ad_id: uploadAction.ad_id || '',
ad_pos: uploadAction.ad_pos || 'kuaiya_minileft_2',
ad_time: new Date().getTime() || 'default',
ad_type: uploadAction.ad_type || 'dianshang',
strategy_id: uploadAction.strategy_id || '',
idea_id: uploadAction.idea_id || '',
plan_id: uploadAction.plan_id || '',
dspData: uploadAction.dspData || 'default',
product_category: uploadAction.product_category || 'undefined' // mini无
};
// console.log("params",params)
var objParams = param_dsp.project + '\t' + param_dsp.data + '\t' + param_dsp.os + '\t' + param_dsp.browser + '\t' + param_dsp.act + '\t' + param_dsp.ad_id + '\t' + param_dsp.ad_pos + '\t' + param_dsp.ad_time + '\t' + param_dsp.ad_type + '\t' + param_dsp.strategy_id + '\t' + param_dsp.idea_id + '\t' + param_dsp.plan_id + '\t' + param_dsp.dspData;
var newUrl = $.base64.encode(encodeURI(objParams));
var url = "http://adtj.kpzip.com/dsp/user_click?code=" + newUrl;
$.getJSON(url).done(function (data) {
});
}
};
w.ds = new SspAndDsp();
/*========== 事件绑定 ==========*/
var _this_b;
function EventBind() {
_this_b = this;
}
EventBind.prototype = {
/**
* s事件绑定
* arr 数据结构
* [target(目标元素选择器),事件名,绑定函数,委托元素选择器(?)]
* @param arr
*/
bindEvent: function (arr) {
(arr && arr.length > 0) && $.each(arr, function (i, v) {
v && (v[3] ? ($(v[3]).on(v[1], v[0], v[2])) : ($(v[0]).on(v[1], v[2])));
})
},
/**
* ssp 点击上报
* @param el
*/
sspUpData: function (el) {
var pos = $(this).attr("data-pos");
w[ds_config[pos].ucn].act = 'click';
w.ds.uploadZhike(w[ds_config[pos].ucn]);
},
/**
* dsp 点击上报
* @param el
*/
dspUpData: function (el) {
var pos = $(this).attr("data-pos");
w[ds_config[pos].ucn].act = 'click';
w.ds.uploadZhike(w[ds_config[pos].ucn]);
w.ds.dspUpload(w[ds_config[pos].ucn]);
}
};
var events = new EventBind();
events.bindEvent([
[".ssp" + ds_config.miniLeft1.muc, "click", events.sspUpData, w.document.body],
[".ssp" + ds_config.miniLeft2.muc, "click", events.sspUpData, w.document.body],
[".ssp" + ds_config.miniRight1.muc, "click", events.sspUpData, w.document.body],
[".ssp" + ds_config.miniRight2.muc, "click", events.sspUpData, w.document.body],
[".ssp" + ds_config.miniRight3.muc, "click", events.sspUpData, w.document.body],
[".dsp" + ds_config.miniLeft1.muc, "click", events.dspUpData, w.document.body],
[".dsp" + ds_config.miniLeft2.muc, "click", events.dspUpData, w.document.body],
[".dsp" + ds_config.miniRight1.muc, "click", events.dspUpData, w.document.body],
[".dsp" + ds_config.miniRight2.muc, "click", events.dspUpData, w.document.body],
[".dsp" + ds_config.miniRight3.muc, "click", events.dspUpData, w.document.body],
]);
})(window);