Listoca

Analytics

Page views and product events with Plausible, Umami, PostHog and others, in the web app, the marketing site and the native app, switched by env and consent-aware.

packages/analytics gives the web app, the marketing site and the native app one analytics API. The provider is picked by VITE_ANALYTICS_PROVIDER (EXPO_PUBLIC_ANALYTICS_PROVIDER in the native app), so switching from Plausible to PostHog is an env change, not a code change. With the variable empty, nothing is loaded at all.

What Listoca uses

Listoca counts with a self-hosted Umami, on the marketing site and in the app (A20 in docs/plans/lists/01-decisions.md). Umami and custom are the providers in this project; the others in the tables below come back with bun run template:add analytics-<name>.

# apps/marketing/.env, and the repository variables the Images workflow builds with
VITE_ANALYTICS_PROVIDER=umami
VITE_UMAMI_WEBSITE_ID=<the website's ID in Umami>
VITE_UMAMI_SCRIPT_URL=https://<your Umami host>/script.js

# apps/native/.env, and the EAS environments
EXPO_PUBLIC_ANALYTICS_PROVIDER=umami
EXPO_PUBLIC_UMAMI_WEBSITE_ID=<the same ID, or a website of the app's own>
EXPO_PUBLIC_UMAMI_SCRIPT_URL=https://<your Umami host>/script.js

Set the script URL in both: without it the provider sends to Umami Cloud, and the privacy policy says the statistics stay on our own server. The policy (apps/marketing/content/legal/privacy.*.mdx) describes what Umami records. It assumes Umami's default of a session salt that changes monthly (SALT_ROTATION unset on the Umami server) and a server at the hosting provider the policy names. Change the text when either changes.

Choose a provider

Set the variables in apps/web/.env and apps/marketing/.env (or your hosting platform). They're public: they end up in the browser.

ProviderVITE_ANALYTICS_PROVIDERSettingsCookies
PlausibleplausibleVITE_PLAUSIBLE_DOMAIN, optional VITE_PLAUSIBLE_SCRIPT_URLno
UmamiumamiVITE_UMAMI_WEBSITE_ID, optional VITE_UMAMI_SCRIPT_URLno
PirschpirschVITE_PIRSCH_CODEno
Vercelvercel(deployed on Vercel with Web Analytics on)no
Google (GA4)googleVITE_GOOGLE_ANALYTICS_IDyes
PostHogposthogVITE_POSTHOG_KEY, optional VITE_POSTHOG_HOST (default EU)yes
MixpanelmixpanelVITE_MIXPANEL_TOKENyes
Customcustomoptional VITE_ANALYTICS_CUSTOM_URLno
# apps/marketing/.env
VITE_ANALYTICS_PROVIDER=plausible
VITE_PLAUSIBLE_DOMAIN=example.com

For the production images, set the same variables where they're built: in .env next to docker-compose.prod.yml, or as repository variables for the Images workflow. Every provider's settings are passed on.

The script URL settings point Plausible or Umami at a self-hosted instance or a proxy on your own domain. A provider whose settings are missing stays off and logs a warning in the browser console.

The app and the site can use different providers, or only one of them can have analytics.

Telling the apps apart

Every page view and event says which app sent it: app is web, marketing or native (set by AnalyticsProvider's app prop). So the apps can share one site or project, with one dashboard for all of them, and you still filter or break down by app. Where it shows up depends on the provider:

ProviderPage viewsEvents
Plausiblecustom property appcustom property app
Umamiby hostname (native in the app)event data app
Pirschby hostnameevent meta app
Vercelby project (each app is its own)event data app
Googleevent parameter appevent parameter app
PostHogsuper property app (autocaptured events too)super property app
Mixpanelsuper property appsuper property app
Customapp in the JSONapp in the JSON

In Plausible, add app as a custom property in the site settings; in Google Analytics, register it as an event-scoped custom dimension. Until then they record it but don't show it in reports.

If you'd rather keep them apart completely, give each app its own site, website ID or project key in its own .env.

Cookieless providers (Plausible, Umami, Pirsch, Vercel) load right away. Providers that set cookies (Google, PostHog, Mixpanel) load only after the visitor accepts the consent banner:

  • The banner appears at the bottom of every page until the visitor answers. Its text is in the i18n shared scope (consent.*). On the marketing site it links to the cookie policy.
  • The answer is stored in the browser (localStorage, per site).
  • Page views and events from before the answer are kept and sent after "Accept", or dropped after "Decline". Nothing is loaded after "Decline".
  • Cookie settings asks again: in the marketing footer, and in the web app's user menus. It's shown only when a cookie-based provider is configured.
  • Changing your mind works at once. Consent is checked on every call, not only before the provider loads: after "Decline" (or while asked again) nothing more is sent, and the provider's own tracking stops too (its optOut: PostHog's and Mixpanel's opt-out, Google's consent mode). "Accept" again resumes it (optIn). Tested in packages/analytics/src/analytics.test.ts.

Update the cookie policy (apps/marketing/content/legal/cookies.*.mdx) to name the provider you use.

What's tracked

  • Page views on every navigation, including client-side ones. A page view sends the URL without its fragment and with only the campaign parameters (utm_*, ref; pageviewUrl in packages/analytics/src/analytics.ts): URLs carry a password reset's token, an email address on /verify and redirect targets, which don't belong with an analytics provider. The SDKs' own copies of the address are kept out too: Mixpanel's $current_url and referrers (property_blacklist), PostHog's masked parameters (token, email, redirect, checkout), and the reset page removes its token from the address bar before any provider starts.
  • Screen views in the native app, as page views of the route's pattern (/list/[id]) whenever it changes. The path stays out: it carries the ids of lists and tasks and an invitation's token (apps/native/src/lib/analytics/screen.ts).
  • The signed-in user (web and native app): identify(user.id) once the session loads, and reset() after signing out. Only the id is sent, never the email. Providers without user profiles ignore it.
  • Product events, typed in packages/analytics/src/events.ts:
EventSent whenProperties
signed_upthe sign-up form succeeds (web, native)method
onboarding_completedonboarding is finished (web, native)
member_invitedan invitation is sentrole
purchase_starteda plan's purchase is openedplan, store
newsletter_subscribedthe newsletter form succeeds (marketing)
contact_submittedthe contact form succeeds (marketing)

In the native app

The native app runs the same core (createAnalytics: the queue, consent, the event catalog) with its own providers in apps/native/src/lib/analytics/, since browser scripts don't run there. Set the variables in apps/native/.env (or your EAS environment):

ProviderEXPO_PUBLIC_ANALYTICS_PROVIDERSettingsAsks for consent
PlausibleplausibleEXPO_PUBLIC_PLAUSIBLE_DOMAIN, optional EXPO_PUBLIC_PLAUSIBLE_SCRIPT_URLno
UmamiumamiEXPO_PUBLIC_UMAMI_WEBSITE_ID, optional EXPO_PUBLIC_UMAMI_SCRIPT_URLno
PostHogposthogEXPO_PUBLIC_POSTHOG_KEY, optional EXPO_PUBLIC_POSTHOG_HOSTyes
Customcustomoptional EXPO_PUBLIC_ANALYTICS_CUSTOM_URLno
  • Plausible and Umami have no React Native SDK, so the app posts to their HTTP APIs (/api/event, /api/send). For a self-hosted instance, set the same script URL as the web app; the API is on its host. Events sent while offline are dropped.
  • PostHog uses posthog-react-native, which stores its queue and the device's id with expo-file-system. Adding it (or expo-application) to a project means a new development build.
  • Google, Mixpanel, Pirsch and Vercel have no native adapter. Selecting one leaves the native app's analytics off with a warning.
  • Consent: with PostHog, a prompt at the bottom of the screen asks before anything is sent. The answer is stored with SecureStore, and "Usage data" in the drawer asks again. Its texts are in the i18n native scope (analyticsConsent.*).

Components call useAnalytics() (and useConsent()) from @listoca/analytics/context, the context the web shares (@listoca/analytics/react re-exports it), with the same typed track. The native AnalyticsProvider (apps/native/src/contexts/analytics-context.tsx) only adds the screen views. The custom provider is the package's custom, with a POST as its transport.

import { useAnalytics } from "@listoca/analytics/context";

const { track } = useAnalytics();
track("signed_up", { method: "email" });

Tracking your own events

Add the event and its properties to AnalyticsEvents in packages/analytics/src/events.ts, then call it from a component:

import { useAnalytics } from "@listoca/analytics/react";

const { track } = useAnalytics();
track("report_exported", { format: "csv" });

track only accepts events from the catalog, with their properties, so names stay consistent across the apps and your dashboards. Outside the provider, or with analytics off, every call is a no-op.

Adding a provider

Each provider is one file in packages/analytics/src/providers/ that returns an adapter. It gets the app's settings and the app it runs in, and sends app with what it tracks:

export const acme: ProviderFactory = ({ env, app }) => {
  if (!env.VITE_ACME_KEY) return null; // missing settings: analytics stays off
  return {
    requiresConsent: false, // true if it sets cookies
    load: () => loadScript("https://cdn.acme.test/script.js", { "data-key": env.VITE_ACME_KEY! }),
    pageview: (url) => window.acme?.page(url, { app }),
    track: (event, properties) => window.acme?.event(event, { app, ...properties }),
    // a provider that sets cookies or tracks on its own: stop and resume it when consent changes
    // optOut: () => window.acme?.optOut(), optIn: () => window.acme?.optIn(),
  };
};

Register it in providers/index.ts and analyticsProviders (config.ts), and add its settings to analyticsEnvKeys (config.ts, which AnalyticsEnv is made of). Then pass them on everywhere build-env.test.ts lists, which fails until you have: both .env.schema files, both src/lib/analytics-env.ts files, both Dockerfiles, docker-compose.prod.yml, .github/workflows/images.yml and .env.production.example. Varlock only includes public variables in the browser bundle where they're written out, and an image only gets the build arguments it's given, so each one is listed by name. providers/custom.ts is a template that posts every page view and event to your own endpoint; the web and the native app share it, each with its own transport (sendBeacon, a POST).

Calls are queued until the provider has loaded, so adapters can assume their script is ready.

For the native app, add an adapter in apps/native/src/lib/analytics/ (an SDK, or post for an HTTP API; plausible.ts is the pattern), register it in providers there, map its settings in analyticsEnv, and add them to apps/native/.env.schema. The template's providers there sit behind template:line analytics-<name> markers, and scripts/template-parts.ts lists their files under the provider's part.

On this page