Analytics for Electron apps and browser extensions
Count screens and events in Electron apps and browser extensions by posting to the collection endpoint with virtual URLs, without creating an identifier.
Apps and extensions don't have normal https:// page URLs, so the browser
snippet isn't the right fit. Send hits to the public collection endpoint
yourself, using virtual URLs on your site's domain.
The collection endpoint#
POST https://privatusanalytics.com/api/event with a text/plain body (no CORS
preflight, no credentials):
js
function privatusHit(type, path, extra = {}) {
return fetch('https://privatusanalytics.com/api/event', {
method: 'POST',
keepalive: true,
credentials: 'omit',
headers: { 'Content-Type': 'text/plain' },
body: JSON.stringify({
s: 'pa_YOURSITEID',
t: type, // 'pageview' or 'event'
u: 'https://app.example.com' + path, // a hostname that's one of your site's domains
l: navigator.language,
w: screen.width,
...extra, // n: event name, p: properties
}),
})
}
privatusHit('pageview', '/settings')
privatusHit('event', '/settings', { n: 'Theme changed', p: { theme: 'dark' } })
The short keys are documented in What the tracker sends.
Electron#
- Send hits from the renderer (so the request carries a normal browser User-Agent), for example on each route change of your app's router.
- Electron's default User-Agent contains
Electron/…, which our bot filter treats as automation. Set a clean User-Agent for your window's session, for example withsession.defaultSession.setUserAgent()removing theElectron/x.y.ztoken, or hits will be filtered as bots. - Add
app.example.com(or whatever host you use inu) to the site's domains.
Browser extensions#
- Send hits from the extension's pages (popup, options page) or background
service worker. Add
https://privatusanalytics.com/*tohost_permissionsinmanifest.jsonfor Manifest V3. - Describe the analytics in your store listing and privacy disclosures. Chrome Web Store and Firefox Add-ons require it even for anonymous usage data.
- Consider an in-extension opt-out that simply stops calling
privatusHit().
Privacy notes#
Nothing here creates an identifier: visits are built exactly as for websites (a daily key from the IP and User-Agent, which is never stored). Don't put user ids, emails or file names in paths or properties.