umami/pages/api/scripts/telemetry.js

19 lines
583 B
JavaScript
Raw Normal View History

2022-08-08 20:31:36 +02:00
import { CURRENT_VERSION, TELEMETRY_PIXEL } from 'lib/constants';
2022-08-02 09:24:17 +02:00
export default function handler(req, res) {
2022-08-08 20:31:36 +02:00
res.setHeader('content-type', 'text/javascript');
if (process.env.DISABLE_TELEMETRY) {
return res.send('/* telemetry disabled */');
}
2022-08-02 09:52:08 +02:00
const script = `
(()=>{const i=document.createElement('img');
2022-08-08 20:31:36 +02:00
i.setAttribute('src','${TELEMETRY_PIXEL}?v=${CURRENT_VERSION}');
2022-08-02 09:52:08 +02:00
i.setAttribute('style','width:0;height:0;position:absolute;pointer-events:none;');
document.body.appendChild(i);})();
`;
2022-08-08 20:31:36 +02:00
return res.send(script.replace(/\s\s+/g, ''));
2022-08-02 09:24:17 +02:00
}