|
@@ -163,46 +163,81 @@ import FingerprintJS from '@fingerprintjs/fingerprintjs';
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
- // 获取指纹ID(本地优先,无则生成并存储)
|
|
|
- async function getfingerprint() {
|
|
|
- let fingerprint = '';
|
|
|
+ const USE_FAKE_FINGERPRINT = true; // 切换开关
|
|
|
+
|
|
|
+ function generateIdList() {
|
|
|
+ const arr = [];
|
|
|
+ for (let i = 0; i < 10; i++) {
|
|
|
+ arr.push('id_' + Math.random().toString(36).substr(2, 10) + Date.now() + '_' + i);
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getFixedIdList() {
|
|
|
+ let idList = [];
|
|
|
try {
|
|
|
- fingerprint = localStorage.getItem('fingerprint_id') || '';
|
|
|
+ idList = JSON.parse(localStorage.getItem('fingerprint_id_list') || '[]');
|
|
|
} catch (e) { }
|
|
|
- if (fingerprint) {
|
|
|
+ if (!Array.isArray(idList) || idList.length !== 10) {
|
|
|
+ idList = generateIdList();
|
|
|
+ try {
|
|
|
+ localStorage.setItem('fingerprint_id_list', JSON.stringify(idList));
|
|
|
+ } catch (e) { }
|
|
|
+ }
|
|
|
+ return idList;
|
|
|
+ }
|
|
|
+
|
|
|
+ async function getFingerprintId() {
|
|
|
+ if (USE_FAKE_FINGERPRINT) {
|
|
|
+ // 每次都从固定的10个ID里随机取一个
|
|
|
+ const idList = getFixedIdList();
|
|
|
+ const idx = Math.floor(Math.random() * 10);
|
|
|
+ const fingerprint = idList[idx];
|
|
|
+ try {
|
|
|
+ localStorage.setItem('fingerprint_id', fingerprint);
|
|
|
+ } catch (e) { }
|
|
|
return fingerprint;
|
|
|
- } else if (FingerprintJS && typeof FingerprintJS.load === 'function') {
|
|
|
+ } else {
|
|
|
+ // 原FingerprintJS方案
|
|
|
+ let fingerprint = '';
|
|
|
try {
|
|
|
- const fp = await FingerprintJS.load();
|
|
|
- const result = await fp.get();
|
|
|
- fingerprint = result.visitorId;
|
|
|
- try {
|
|
|
- localStorage.setItem('fingerprint_id', fingerprint);
|
|
|
- } catch (e) { }
|
|
|
+ fingerprint = localStorage.getItem('fingerprint_id') || '';
|
|
|
+ } catch (e) { }
|
|
|
+ if (fingerprint) {
|
|
|
return fingerprint;
|
|
|
- } catch (e) {
|
|
|
+ } else if (FingerprintJS && typeof FingerprintJS.load === 'function') {
|
|
|
+ try {
|
|
|
+ const fp = await FingerprintJS.load();
|
|
|
+ const result = await fp.get();
|
|
|
+ fingerprint = result.visitorId;
|
|
|
+ try {
|
|
|
+ localStorage.setItem('fingerprint_id', fingerprint);
|
|
|
+ } catch (e) { }
|
|
|
+ return fingerprint;
|
|
|
+ } catch (e) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
return '';
|
|
|
}
|
|
|
- } else {
|
|
|
- return '';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取UTM参数(异步,带指纹,本地唯一)
|
|
|
UtmTracker.prototype.getParamsAsync = async function () {
|
|
|
const params = this.getParams();
|
|
|
- params.fingerprint = await getfingerprint();
|
|
|
+ params.fingerprint = await getFingerprintId();
|
|
|
return params;
|
|
|
};
|
|
|
|
|
|
// 发送请求(自动带指纹,异步,指纹本地唯一)
|
|
|
- UtmTracker.prototype.send = async function (data) {
|
|
|
+ UtmTracker.prototype.send = async function (data1) {
|
|
|
const cfg = this.config || {};
|
|
|
- let payload = data;
|
|
|
+ let payload = data1;
|
|
|
if (!payload) {
|
|
|
payload = await this.getParamsAsync();
|
|
|
} else if (!payload.fingerprint) {
|
|
|
- payload.fingerprint = await getfingerprint();
|
|
|
+ payload.fingerprint = await getFingerprintId();
|
|
|
}
|
|
|
if (!cfg.reportUrl) return;
|
|
|
fetch(cfg.reportUrl, {
|
|
@@ -214,10 +249,22 @@ import FingerprintJS from '@fingerprintjs/fingerprintjs';
|
|
|
// 假设res为Response对象,需要解析json
|
|
|
if (typeof res.json === 'function') {
|
|
|
res.json().then(data => {
|
|
|
+
|
|
|
if (data.code == 1) return
|
|
|
- if (data.data && data.data.downloadUrl) {
|
|
|
-
|
|
|
- if (data.data.type === 'link') {
|
|
|
+ if (data.data && data.data.downloadUrl) {
|
|
|
+ if (data.data.type === '1' || data.data.type === '2') {
|
|
|
+ // 读取本地存储的跳转次数
|
|
|
+ const jumpContent = window.localStorage.getItem('jump_content') || 0;
|
|
|
+ // 获取上次跳转的应用id
|
|
|
+ const appId = window.localStorage.getItem('app_id');
|
|
|
+ // 读取上次跳转的类型
|
|
|
+ const lastType = window.localStorage.getItem('last_type');
|
|
|
+
|
|
|
+ if (data.data.type === '1' && appId == data.data.appId && lastType == data.data.type) {
|
|
|
+ alert('相同应用ID,已跳转过,跳转取消');
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// 倒计时弹窗
|
|
|
let countdown = 3;
|
|
|
const countdownMask = document.createElement('div');
|
|
@@ -254,14 +301,23 @@ import FingerprintJS from '@fingerprintjs/fingerprintjs';
|
|
|
if (countdown <= 0) {
|
|
|
clearInterval(timer);
|
|
|
document.body.removeChild(countdownMask);
|
|
|
- // 跳转
|
|
|
- console.log(data.data.downloadUrl);
|
|
|
- window.location.href = data.data.downloadUrl
|
|
|
- return
|
|
|
+
|
|
|
+ // 跳转逻辑变更
|
|
|
+ if(appId == data.data.appId){
|
|
|
+ window.localStorage.setItem('last_type', data.data.type);
|
|
|
+ window.localStorage.setItem('jump_content', parseInt(jumpContent) + 1);
|
|
|
+ window.location.href = data.data.downloadUrl;
|
|
|
+ }else{
|
|
|
+ window.localStorage.setItem('last_type', data.data.type);
|
|
|
+ window.localStorage.setItem('app_id', data.data.appId);
|
|
|
+ window.localStorage.setItem('jump_content', 1);
|
|
|
+ window.location.href = data.data.downloadUrl;
|
|
|
+ }
|
|
|
}
|
|
|
- }, 1000);
|
|
|
- return
|
|
|
+ }, 1000);
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
|
|
|
|
|
|
|