feat: add privacy-safe production player pageviews
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/* Production pageviews only. Never pass application/browser DOM data to Umami. */
|
||||
(() => {
|
||||
'use strict';
|
||||
const hostname = "player.nenasets.com";
|
||||
const website = "dc1b14a6-d1ba-4802-b895-553b3c81c677";
|
||||
const url = "/";
|
||||
const title = "Alta Export Player";
|
||||
const paths = ["/"];
|
||||
const eligible = () => window.location.protocol === 'https:'
|
||||
&& window.location.hostname === hostname && window.location.port === ''
|
||||
&& paths.includes(window.location.pathname);
|
||||
if (!eligible() || window.__altaPageviewLoaded) return;
|
||||
window.__altaPageviewLoaded = true;
|
||||
// Rebuild, don't spread the input: no identity, event properties, referrer,
|
||||
// customer title, query, fragment, form, filename or upload data can survive.
|
||||
window.altaSafePageview = (type, payload) => {
|
||||
if (!eligible() || type !== 'event' || !payload || payload.name) return null;
|
||||
return { website, hostname, url, title, referrer: '',
|
||||
screen: /^\d{1,5}x\d{1,5}$/.test(payload.screen) ? payload.screen : undefined,
|
||||
language: /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/.test(payload.language) ? payload.language : undefined };
|
||||
};
|
||||
const tracker = document.createElement('script');
|
||||
tracker.src = 'https://umami.nenasets.com/script.js';
|
||||
tracker.defer = true;
|
||||
tracker.referrerPolicy = 'no-referrer';
|
||||
for (const [key, value] of Object.entries({
|
||||
'website-id': website, domains: hostname, 'auto-track': 'false',
|
||||
'exclude-search': 'true', 'exclude-hash': 'true',
|
||||
'fetch-credentials': 'omit', 'before-send': 'altaSafePageview'
|
||||
})) tracker.setAttribute('data-' + key, value);
|
||||
let sent = false;
|
||||
tracker.onload = () => {
|
||||
if (!sent && eligible() && window.umami) {
|
||||
sent = true;
|
||||
window.umami.track();
|
||||
}
|
||||
};
|
||||
document.head.appendChild(tracker);
|
||||
})();
|
||||
Reference in New Issue
Block a user