//获取浏览器类型
var ua = navigator.userAgent;
//手机型号
var mm = ['iPhone', 'iPad', 'iPod', 'Nexus', 'BenQ-Siemens', 'Meizu', 'Xiaomi', 'BlackBerry', 'CoolPad', 'Dell', 'HTC', 'Huawei', 'Kindle', 'K-Touch', 'Lenovo', 'LG', 'Motorola', 'Nintendo', 'Nokia', 'Onda', 'OPPO', 'OLPC', 'Palm', 'PlayStation', 'Samsung', 'SonyXperia', 'SonyEricsson', 'vivo', 'ZTE', 'UbuntuPhone', 'UbuntuTablet', 'WindowsPhone']
//提交布点方法
function playevent(json){
//时间
if(json.time == undefined){
json.time = 'No Time';
}
//事件code,默认p.nw.pv
if(json.code == undefined){
json.code = 'p.nw.pv';
}
//来源页面flg
if(json.flg == undefined){
json.flg = 'No Flg';
}
//uuid
if(json.uuid == undefined){
json.uuid = 'No UUID'
}
//ip
if(json.ip == undefined){
json.ip = 'No IP'
}
//事件描述
if(json.desc == undefined){
json.desc = '|!|'
}
//数据
var edata = json.time+','+json.code +',' + isPc() + ',' + getDeviceInfo(ua, mm) + ','+ isBrowser() + ',' + json.flg + ','+ sources() +',' + json.ip + ',' + json.uuid +','+ json.desc;
console.log(edata)
//提交数据
$.ajax({
url : json.url,
data : {"entCE.ceP0":"fitWeb","entCE.ceP1":edata},
dataType : 'jsonp',
success : function(){
if(json.success != undefined){
json.success();
}
}
})
//alert(edata)
}
//判断pc还是移动端,如果是移动端,是安卓还是苹果
function isPc() {
if ((ua.match(/(Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone)/i))) {
if (/iPhone|iPad|iPod/.test(ua)) {
return 'ios'
} else if (/Android/.test(ua)) {
return 'android'
}
}else{
return 'PC'
}
}
//获取浏览器类型
function isBrowser(){
if (ua.indexOf("Opera") > -1) {
return "Opera浏览器"
}; //判断是否Opera浏览器
if (ua.indexOf("Firefox") > -1) {
return "Firefox浏览器";
} //判断是否Firefox浏览器
if (ua.indexOf("Chrome") > -1){
return "Chrome浏览器";
}
if (ua.indexOf("Safari") > -1) {
return "Safari浏览器";
} //判断是否Safari浏览器
if (ua.indexOf("compatible") > -1 && ua.indexOf("MSIE") > -1 && !isOpera) {
return "IE浏览器";
}; //判断是否IE浏览器
if (ua.match(/WeiBo/i) == "WeiBo") {
return "WeiBo浏览器";
}
if (ua.match(/QQ/i) == "QQ") {
return "QQ浏览";
}
if (ua.match(/MicroMessenger/i) == "MicroMessenger") {
return "Weixin浏览器";
}
return '未知浏览器';
}
//获取来源渠道
function sources(){
var f = getQueryString('f');
if(f != null){
return f;
}
var wxFrom = getQueryString('from');
if(wxFrom != null){
if(wxFrom == 'groupmessage'){
return 'Wechat';
}else if(wxFrom == 'singlemessage'){
return 'Weixin';
}
}
if(f == null && wxFrom == null){
if (ua.match(/QQ/i) == "QQ") {
return "QQ";
}
if (ua.match(/MicroMessenger/i) == "MicroMessenger") {
return "Weixin";
}
return 'FitIdx'
}
}
//获取手机品牌
function getDeviceInfo(ua, a) {
var devices = a,
device,
c,
i = 0;
while (device = devices[i++]) {
d = new RegExp("(" + device + ")", "i");
if (d.test(ua.toLowerCase()))c = device;
}
switch (c) {
case undefined:
c = 'Android';
break;
case 'iPhone OS':
c = 'iOS';
break;
}
return c;
}
//获取url参数
function getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}