change get ip method
parent
1ca468cce1
commit
3c906d066b
|
@ -76,9 +76,9 @@ export async function getCountry(req, ip) {
|
||||||
return result?.country?.iso_code;
|
return result?.country?.iso_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getClientInfo(req, { screen }) {
|
export async function getClientInfo(req, { screen, ip }) {
|
||||||
const userAgent = req.headers['user-agent'];
|
const userAgent = req.headers['user-agent'];
|
||||||
const ip = getIpAddress(req);
|
// const ip = getIpAddress(req);
|
||||||
const country = await getCountry(req, ip);
|
const country = await getCountry(req, ip);
|
||||||
const browser = browserName(userAgent);
|
const browser = browserName(userAgent);
|
||||||
const os = detectOS(userAgent);
|
const os = detectOS(userAgent);
|
||||||
|
|
|
@ -70,6 +70,7 @@
|
||||||
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 */
|
||||||
|
|
||||||
|
@ -79,9 +80,26 @@
|
||||||
screen,
|
screen,
|
||||||
language,
|
language,
|
||||||
url: currentUrl,
|
url: currentUrl,
|
||||||
|
ip,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getClientIPAddress = () => {
|
||||||
|
if (ip) return ip;
|
||||||
|
fetch('https://api64.ipify.org/?format=json')
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => {
|
||||||
|
ip = data.ip;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
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, {
|
||||||
|
@ -193,6 +211,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Global */
|
/* Global */
|
||||||
|
getClientIPAddress();
|
||||||
|
|
||||||
if (!window.umami) {
|
if (!window.umami) {
|
||||||
const umami = eventValue => trackEvent(eventValue);
|
const umami = eventValue => trackEvent(eventValue);
|
||||||
|
|
Loading…
Reference in New Issue