Dok.
Bla i dokumentasjonen

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.

Vis som Markdown

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://privatusstats.com/api/event with a text/plain body (no CORS preflight, no credentials):

js
function privatusHit(type, path, extra = {}) {
  return fetch('https://privatusstats.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: typeof screen === 'undefined' ? undefined : screen.width, // no screen in a service worker
      ...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.

The endpoint always responds with 202, whether the hit was stored or dropped. A hit is dropped when u is not an http:// or https:// URL, when its hostname is not one of the site's domains (or a subdomain of one), or when the request looks like a bot.

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 the bot filter treats as automation. Set a clean User-Agent for your window's session, for example with session.defaultSession.setUserAgent() removing the Electron/x.y.z token, or hits are dropped as bots while the site's bot filtering is on.
  • Add app.example.com (or whatever host you use in u) to the site's domains.

Browser extensions#

  • Send hits from your extension's pages (popup, options page) or background service worker. Add https://privatusstats.com/* to host_permissions in manifest.json for 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.