Skip to content

Commit

Permalink
Merge pull request #424 from postmanlabs/MARKENG-3397-PROD
Browse files Browse the repository at this point in the history
[MARKENG-3397][c] add fingerprintJs & pmt.user variable [cherry-pick from develop, for PROD]
  • Loading branch information
oswish authored Jun 14, 2024
2 parents f5a7df2 + 15799fa commit 9cc80ac
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
24 changes: 18 additions & 6 deletions bff.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,30 @@ const UACode = 'G-X3S374SEP0';
const prefetch = async () => {
const script = `
${pmt}
const fpPromise = import('/fp.js')
.then(FingerprintJS => FingerprintJS.load());
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');
const initPmt = function() {
window.pmt('scalp', [
'pm-analytics',
'load',
document.location.pathname
]);
window.pmt('trackClicks');
}
fpPromise
.then(fp => fp.get())
.then(result => {
window.pmt('set', ['user', {fingerprint: result}]);
initPmt();
})
.catch(() => initPmt());
var _ga = (document.cookie.match('(^|;) ?_ga=([^;]*)(;|$)') || [])[2];
var _PUB_ID = (document.cookie.match('(^|;) ?_PUB_ID=([^;]*)(;|$)') || [])[2];
Expand Down
3 changes: 3 additions & 0 deletions build/bffData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ const fs = require('fs');
const fetch = require('node-fetch');
const path = require('path');
const sh = require('shelljs');
const cacheCdn = require('./cacheCdn');

const TIME = (new Date()).getTime();
const api = 'https://www.postman.com/mkapi';
const url = `${api}/worker.json?${TIME}`;

cacheCdn('https://fpjscdn.net/v3/vytU6aPKbOCzx72ch0fn', 'fp');

const bffData = () => new Promise((resolve) => {
fetch(url).then((res) => {
res.text().then((resp) => {
Expand Down
23 changes: 23 additions & 0 deletions build/cacheCdn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require('fs');
const path = require('path');
const sh = require('shelljs');

async function cacheCdn(url, name) {
const fetch = (await import('node-fetch')).default;

sh.exec('mkdir -p public');

fetch(url).then((res) => {
res.text().then((resp) => {
if (resp) {
fs.writeFile(path.join('public', `${name}.js`), resp, (err) => {
if (err) {
throw err;
}
});
}
});
});
}

module.exports = cacheCdn;
3 changes: 3 additions & 0 deletions build/fp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const cacheCdn = require('./cacheCdn');

cacheCdn('https://fpjscdn.net/v3/vytU6aPKbOCzx72ch0fn', 'fp');

0 comments on commit 9cc80ac

Please sign in to comment.