edit tracker script to work under SSR sites

pull/1644/head
Sergei Meza 2022-10-18 11:01:34 +09:00
parent 3c906d066b
commit bf4de2fbf5
2 changed files with 42 additions and 31 deletions

View File

@ -84,11 +84,18 @@
}); });
const getClientIPAddress = () => { const getClientIPAddress = () => {
if (ip) return ip; return new Promise(res => {
if (ip) {
res(ip);
return;
}
fetch('https://api64.ipify.org/?format=json') fetch('https://api64.ipify.org/?format=json')
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
ip = data.ip; ip = data.ip;
res(ip);
return;
});
}); });
}; };
@ -211,8 +218,7 @@
}; };
/* Global */ /* Global */
getClientIPAddress(); getClientIPAddress().then(() => {
if (!window.umami) { if (!window.umami) {
const umami = eventValue => trackEvent(eventValue); const umami = eventValue => trackEvent(eventValue);
umami.trackView = trackView; umami.trackView = trackView;
@ -243,4 +249,5 @@
update(); update();
} }
});
})(window); })(window);

View File

@ -58,7 +58,11 @@ document.head.appendChild(script);
// }; // };
// analytics.subscribe('page_viewed', async event => { // analytics.subscribe('page_viewed', async event => {
// lemonsquare.trackView(event.url, event.referrer); // lemonsquare.trackView(
// event.context.location.pathname,
// event.context.document.referrer,
// WEBSITE_ID,
// );
// }); // });
// // product_viewed Event // // product_viewed Event