【修改】调整下载传参
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
const config = {
|
||||
webId: '',
|
||||
// QuickTracking
|
||||
appKey: '54x8kny36dp66gbiqngsdnmu',
|
||||
trackHost: 'api_ubtas.faw-vw.com',
|
||||
sdkUrl: 'https://o.alicdn.com/QTSDK/quicktracking-sdk/qt_web.umd.js'
|
||||
}
|
||||
export default config
|
||||
@@ -0,0 +1,134 @@
|
||||
import config from '@/utils/env'
|
||||
import store from '@/store'
|
||||
|
||||
console.log(config)
|
||||
const {
|
||||
appKey,
|
||||
trackHost,
|
||||
sdkUrl
|
||||
} = config
|
||||
|
||||
export const EventType = {
|
||||
Exp: 'EXP',
|
||||
Click: 'CLK',
|
||||
Other: 'OTHER'
|
||||
}
|
||||
|
||||
export function init() {
|
||||
if (!window.aplus_queue) {
|
||||
initQueue()
|
||||
loadQuickTrackSDK()
|
||||
.then(() => {
|
||||
setUserInfo()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function sendTrackEvent({
|
||||
eventName,
|
||||
pageName = eventName,
|
||||
eventType = EventType.Click,
|
||||
params
|
||||
}) {
|
||||
console.log('qt event', eventName, pageName, eventType, params)
|
||||
window.aplus_queue.push({
|
||||
action: 'aplus.record',
|
||||
arguments: [eventName, eventType, {
|
||||
...params,
|
||||
page_name: pageName
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
export function sendTrack({
|
||||
eventName,
|
||||
pageName = eventName,
|
||||
params
|
||||
}) {
|
||||
console.log('qt tracking', eventName, pageName, params)
|
||||
window.aplus_queue.push({
|
||||
action: 'aplus.sendPV',
|
||||
arguments: [{
|
||||
is_auto: false
|
||||
}, {
|
||||
// ts: Date.now(),
|
||||
// path: eventName, // 当前page的url
|
||||
page_name: pageName,
|
||||
...params
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
function initQueue() {
|
||||
window.aplus_queue = []
|
||||
// 手动 PV
|
||||
window.aplus_queue.push({
|
||||
action: 'aplus.setMetaInfo',
|
||||
arguments: ['aplus-waiting', 'MAN']
|
||||
})
|
||||
// 集成应用的appKey
|
||||
window.aplus_queue.push({
|
||||
action: 'aplus.setMetaInfo',
|
||||
arguments: ['appKey', appKey]
|
||||
})
|
||||
// 如果是私有云部署还需要在上面那段JS后面紧接着添加日志域名埋点
|
||||
if (trackHost) {
|
||||
window.aplus_queue.push({
|
||||
action: 'aplus.setMetaInfo',
|
||||
arguments: ['aplus-rhost-v', trackHost]
|
||||
})
|
||||
}
|
||||
// 关闭全埋点
|
||||
window.aplus_queue.push({
|
||||
action: 'aplus.setMetaInfo',
|
||||
arguments: ['aplus-autotrack-enabled', false]
|
||||
})
|
||||
window.aplus_queue.push({
|
||||
action: 'aplus.setMetaInfo',
|
||||
arguments: ['_hold', 'BLOCK']
|
||||
})
|
||||
}
|
||||
|
||||
async function loadQuickTrackSDK() {
|
||||
// qt的库回覆盖window.history的函数 pushState, replaceState 函数并导致IE11报错
|
||||
// 这里覆盖回去
|
||||
const nativePushState = window.history.pushState
|
||||
const nativeReplaceState = window.history.replaceState
|
||||
return new Promise((resolve) => {
|
||||
const $scriptInDOM = document.getElementsByTagName('script')[0]
|
||||
const $script = document.createElement('script')
|
||||
$script.async = true
|
||||
$script.id = 'beacon-aplus'
|
||||
$script.src = sdkUrl
|
||||
$script.onload = () => {
|
||||
// qt库内部在body渲染之后延时51,这里延时200应该足以覆盖
|
||||
sleep(200).then(() => {
|
||||
window.history.pushState = nativePushState
|
||||
window.history.replaceState = nativeReplaceState
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
$scriptInDOM.parentNode.insertBefore($script, $scriptInDOM)
|
||||
})
|
||||
}
|
||||
|
||||
async function setUserInfo() {
|
||||
const userInfo = store.getters.userInfo
|
||||
if (userInfo) {
|
||||
window.aplus_queue.push({
|
||||
action: 'aplus.setMetaInfo',
|
||||
arguments: ['_user_id', userInfo.usid]
|
||||
})
|
||||
}
|
||||
window.aplus_queue.push({
|
||||
action: 'aplus.setMetaInfo',
|
||||
arguments: ['_hold', 'START']
|
||||
})
|
||||
}
|
||||
|
||||
async function sleep(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user