47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import {genSaltSync, hashSync} from 'bcryptjs';
|
|
|
|
export enum TrackingType {
|
|
/** 进入游戏 */
|
|
Open = 'open',
|
|
/** 复活 */
|
|
Revive = 'revive',
|
|
/** 锤子 */
|
|
Hammer = 'hammer',
|
|
/** 画笔 */
|
|
Brush = 'brush',
|
|
/** 重置 */
|
|
Reset = 'reset',
|
|
}
|
|
|
|
const KEY = `sssssssssk`;
|
|
|
|
export class TrackingManager {
|
|
public static async send(type: TrackingType) {
|
|
const salt = genSaltSync(10);
|
|
const hash = hashSync(KEY, salt);
|
|
|
|
const formData = new FormData();
|
|
formData.append('listener', type);
|
|
const res = await fetch('https://api.ad.game.06zk.com/app/anchor', {
|
|
method: "POST",
|
|
headers: {
|
|
Key: hash,
|
|
Href: location.href
|
|
},
|
|
body: formData
|
|
});
|
|
|
|
const data = await res.json();
|
|
|
|
if (data.code === 200) {
|
|
console.log(`上报${type}成功`);
|
|
} else {
|
|
console.log(`上报${type}失败`);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!CC_EDITOR) {
|
|
TrackingManager.send(TrackingType.Open);
|
|
}
|