引入文件
import Vue from "vue"
/**
*/
import axios from 'axios';
const URL = 'https://idapi.ipmotionmc.com/dapf-receive/receive/push';
const projectMark = ''; // 每个项目自己配置
const secret = ''; // 每个项目自己配置
let loginUserId = ''
const href = location.href
const hostname = location.hostname
let user_country = ''
let user_province = ''
let user_city = ''
/**
-
@param {*} params 格式为
{
"eventKey": "", 事件标识 (必填)
"eventTime": 0, 事件时间,默认为系统时间(选填)
"eventVariable": {}, 事件级变量(选填)
"loginUserId": "", 登录用户ID(必填)
"projectMark": "" 项目标识(必填)
}
*/
const from_searchs = [['百度', 'www.baidu.com'], ['谷歌', 'www.google.com'], ['搜狗', 'www.sogou.com'], ['bing', 'cn.bing.com'], ['神马搜索', 'm.sm.cn'], ['360搜索', 'www.so.com'], ['头条', 'so.toutiao.com']] // 搜索引擎来源
const referrer = document.referrer || location.href
let fromdomain = location.hostname
if (referrer && referrer.split('//')[1]) {
fromdomain = referrer.split('//')[1].split('/')[0]
}
const jsAPI = async (eventType, eventKey, params) => {
loginUserId = localStorage.getItem('user') JSON.parse(localStorage.getItem('user')).uuid : ''
loginUserId = loginUserId || localStorage.getItem('loginUserId') || parseInt(Math.random() * 1000000) + '' + new Date().getTime()
localStorage.setItem('loginUserId', loginUserId)
const pubParams = {
from_type: document.referrer 'search' : 'direct_access',
fromdomain,
fromurl: referrer,
from_search: from_searchs.find(x => referrer.includes(x[1])) from_searchs.find(x => referrer.includes(x[1]))[0] : '',
visitdomain: location.hostname,
page_name: location.href,
landingpageurl: href,
landingdomain: hostname,
is_new_visitor: localStorage.getItem('loginUserId') false : true
}axios.post(URL, { projectMark, eventTime: new Date().getTime(), eventKey, eventType: eventType === 'track' 2 : 1, eventVariable: { ...params, ...pubParams, ...userObj, businessLinesMark: 'yz' // 云展 yz 预热h5 hoth5 }, loginUserId, }, { headers: { projectMark, secret // 每个项目自己配置 } });
} catch(err) {
console.log(err, '埋点')
}
};
Vue.prototype.$jsAPI = jsAPI;