fix ip getter
parent
d0f5c6dec7
commit
0336f41e12
|
@ -45,7 +45,8 @@ export async function getSession(req) {
|
||||||
throw new Error(`Website not found: ${website_uuid}`);
|
throw new Error(`Website not found: ${website_uuid}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
|
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
||||||
|
const { userAgent, browser, os, country, device } = await getClientInfo(req, payload);
|
||||||
|
|
||||||
let session_uuid = uuid(websiteId, hostname, ip, userAgent);
|
let session_uuid = uuid(websiteId, hostname, ip, userAgent);
|
||||||
if (process.env.CROSSDOMAIN_TRACKING) {
|
if (process.env.CROSSDOMAIN_TRACKING) {
|
||||||
|
|
|
@ -71,7 +71,6 @@
|
||||||
let currentUrl = `${pathname}${search}`;
|
let currentUrl = `${pathname}${search}`;
|
||||||
let currentRef = document.referrer;
|
let currentRef = document.referrer;
|
||||||
let cache;
|
let cache;
|
||||||
let ip;
|
|
||||||
|
|
||||||
/* Collect metrics */
|
/* Collect metrics */
|
||||||
|
|
||||||
|
@ -81,40 +80,9 @@
|
||||||
screen,
|
screen,
|
||||||
language,
|
language,
|
||||||
url: currentUrl,
|
url: currentUrl,
|
||||||
ip,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const getClientIPAddress = () => {
|
|
||||||
return new Promise((res, rej) => {
|
|
||||||
if (window.ip || ip) {
|
|
||||||
ip = ip || window.ip;
|
|
||||||
res(ip);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log('fetching user ip');
|
|
||||||
fetch('https://api64.ipify.org/?format=json')
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(data => {
|
|
||||||
ip = data.ip;
|
|
||||||
window.ip = data.ip;
|
|
||||||
res(ip);
|
|
||||||
return;
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
rej(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const collect = (type, payload) => {
|
const collect = (type, payload) => {
|
||||||
if (!ip) {
|
|
||||||
setTimeout(() => {
|
|
||||||
collect(type, payload);
|
|
||||||
}, 100);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trackingDisabled()) return;
|
if (trackingDisabled()) return;
|
||||||
|
|
||||||
return fetch(endpoint, {
|
return fetch(endpoint, {
|
||||||
|
@ -226,38 +194,36 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Global */
|
/* Global */
|
||||||
getClientIPAddress().then(() => {
|
if (!window.umami) {
|
||||||
if (!window.umami) {
|
const umami = eventValue => trackEvent(eventValue);
|
||||||
const umami = eventValue => trackEvent(eventValue);
|
umami.trackView = trackView;
|
||||||
umami.trackView = trackView;
|
umami.trackEvent = trackEvent;
|
||||||
umami.trackEvent = trackEvent;
|
|
||||||
|
|
||||||
window.umami = umami;
|
window.umami = umami;
|
||||||
window.lemonsquare = umami;
|
window.lemonsquare = umami;
|
||||||
|
|
||||||
console.log('LemonSquare is ready to track your events!');
|
console.log('LemonSquare is ready to track your events!');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start */
|
/* Start */
|
||||||
|
|
||||||
if (autoTrack && !trackingDisabled()) {
|
if (autoTrack && !trackingDisabled()) {
|
||||||
history.pushState = hook(history, 'pushState', handlePush);
|
history.pushState = hook(history, 'pushState', handlePush);
|
||||||
history.replaceState = hook(history, 'replaceState', handlePush);
|
history.replaceState = hook(history, 'replaceState', handlePush);
|
||||||
|
|
||||||
const update = () => {
|
const update = () => {
|
||||||
if (document.readyState === 'complete') {
|
if (document.readyState === 'complete') {
|
||||||
trackView();
|
trackView();
|
||||||
|
|
||||||
if (cssEvents) {
|
if (cssEvents) {
|
||||||
addEvents(document);
|
addEvents(document);
|
||||||
observeDocument();
|
observeDocument();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
document.addEventListener('readystatechange', update, true);
|
document.addEventListener('readystatechange', update, true);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|
Loading…
Reference in New Issue