This repository has been archived by the owner on Jan 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathbff.js
125 lines (104 loc) · 3.18 KB
/
bff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const fs = require('fs');
const fetch = require('node-fetch');
const sh = require('shelljs');
sh.config.silent = true;
const pmt = sh.exec('cat pmt.js').stdout.split('\n').shift();
sh.config.silent = false;
function cacheCdn(url, name) {
sh.exec('mkdir -p public');
fetch(url).then((res) => {
res.text().then((resp) => {
if (resp) {
fs.writeFile(`${name}.js`, resp, (err) => {
if (err) {
throw err;
}
});
}
});
});
}
const UACode = 'G-X3S374SEP0';
const prefetch = async () => {
const script = `
${pmt}
setTimeout(function(){
var propertyName = 'covid-19-apis';
if (window.pmt) {
window.pmt('setScalp', [{
property: propertyName
}]);
window.pmt('scalp', [
'pm-analytics',
'load',
document.location.pathname
]);
window.pmt('trackClicks');
var _ga = (document.cookie.match('(^|;) ?_ga=([^;]*)(;|$)') || [])[2];
var _PUB_ID = (document.cookie.match('(^|;) ?_PUB_ID=([^;]*)(;|$)') || [])[2];
var dnt = (parseInt(navigator.doNotTrack) === 1 || parseInt(window.doNotTrack) === 1 || parseInt(navigator.msDoNotTrack) === 1 || navigator.doNotTrack === "yes");
window.pmt('log', ['navigator.doNotTrack: ' + dnt]);
if(!dnt) {
load('/_ga.js');
load('/_gtag.js');
var d = 1000, int;
var int = setInterval(function(){
if (window.ga) {
window.pmt('set', ['ga', function(){
if (typeof window.ga === 'function') {
window.ga.apply(this, arguments);
}
return window.ga;
}]);
var sitename = document.location.hostname;
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
window.gtag = gtag;
gtag('js', new Date());
gtag('config', '${UACode}');
window.pmt('ga', ['${UACode}', sitename]);
window.pmt('log', ['initialized GA: ' + sitename + ' (' + '${UACode}' + ')']);
window._iaq = window._iaq || {};
if (!window.pmt.status) {
var status = _PUB_ID && { LoggedIn: _PUB_ID } || { Anonymous: _ga || 'private' };
window.pmt('set', ['status', status]);
var key = Object.keys(window.pmt('status'))[0];
window.ga('send', 'event', key, 'User', status);
window.pmt('log', ['PM user log-in status: ' + JSON.stringify(status)]);
}
clearInterval(int);
}
}, d);
}
}
}, 1000);
function load(src, cb) {
var e = document.createElement('script');
e.src = src;
e.async = true;
e.onreadystatechange = function(){
if (this.readyState === 'complete' || this.readyState === 'loaded') {
if (typeof cb === 'function') {
cb();
}
}
};
e.onload = cb;
document.head.appendChild(e);
}
`
|| `
console.info('Postman OSS');
`;
fs.writeFile('bff.json', JSON.stringify({ script }), (err) => {
if (err) {
throw err;
}
cacheCdn('https://www.google-analytics.com/analytics.js', '_ga');
cacheCdn('https://www.googletagmanager.com/gtag/js', '_gtag');
setTimeout(() => {
sh.exec('cp _g* public/');
}, 4000);
});
};
prefetch();