Docs
Parcourir la documentation

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.

Voir en 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://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 with session.defaultSession.setUserAgent() removing the Electron/x.y.z token, or hits will be filtered as bots.
  • Add app.example.com (or whatever host you use in u) 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/* 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.