On this page

Product analytics

Track what users do in your web and mobile apps, linked to the signed-in user: active users, funnels, retention and breakdowns, stored in your project’s database.

LimitFreeProScaleEnterprise
Analytics events per month50,0001,000,00010,000,000100,000,000
Analytics events kept30 days90 days365 days365 days

Analytics counts what users do in your apps. The SDK sends the events you track, linked to the signed-in user. Before sign-in it uses an anonymous id for the device or browser, and when the user signs in, what they did before is merged into them. Studio shows active users, top events, an event over time broken down by release, platform, country, OS or one of its properties, funnels, weekly retention and one user’s events. With crash reporting on, crash-free users show next to the active users.

#Set it up

  1. Open Studio › Analytics and click Turn on analytics.
  2. Call analytics.start() once when your app starts, then track() what matters. Nothing is sent before start(). If you ask your users for consent, call it after they agreed. Events tracked before that wait in memory.
import { createClient } from 'stitchdb-js'
const stitchdb = createClient(STITCHDB_URL, STITCHDB_ANON_KEY)

stitchdb.analytics.start({ release: '1.4.0' }) // page views ($pageview) are tracked for you on the web
stitchdb.analytics.track('purchase', { plan: 'pro', amount: 29 })

Events are sent in the background in batches of up to 100, every 10 seconds or when 20 are waiting, and when a page is hidden. While the device is offline they are kept (localStorage, shared preferences or a file) and sent later. An event name is letters, digits, _ $ . : - / and spaces, up to 64 characters. Properties are a JSON object of up to 8 KB, and flat values are the easiest to break down by.

#What Studio shows

ViewWhat it is
Active usersUsers with at least one event per day (UTC), DAU, WAU (7 days), MAU (30 days), DAU/MAU and new users. Kept 400 days.
Top eventsThe most frequent events of the last 30 days, with how many users did them.
Event over timeOne event per day, week or month as events or users, over 7 to 90 days, broken down by release, platform, country, OS or one of its properties (the top 10 values, the rest as other).
Funnel2 to 6 events in order: the users who did the first in the period, then each next one after it, within a window of the first (1 hour to 30 days), with the median time to each step.
RetentionUsers by the week they were first seen, and the share active again 1, 2, … weeks later (up to 12 weeks).
One userThe latest events of a user, by their id.

Country comes from the device’s region setting (the browser language or the phone’s locale), not from the IP address.

#Privacy

  • Values of properties named like passwords, tokens, secrets, keys and cookies are replaced with [scrubbed], and e-mail addresses and JWTs are removed. You can add your own field names in the settings.
  • analytics.optOut(): the user’s events are deleted, and their new ones are dropped by the SDK and refused by StitchDB. The device remembers this. optIn() undoes it.
  • The user is taken from their token. An app cannot track as another user. Only the service key may name one, with user_id (for events from your server).
  • Events are stored in your project’s database in the schema _stitch_analytics, not in a third-party service. You can query them with SQL and delete them like any other data.

#From your server and SQL

bash
# events from your server, for a user (service key)
curl -X POST 'https://<ref>.p.stitchdb.com/analytics/v1/track' \
  -H "apikey: $SERVICE_KEY" -H "Authorization: Bearer $SERVICE_KEY" -H 'Content-Type: application/json' \
  -d '{"user_id":"<user id>","events":[{"name":"subscription_renewed","props":{"plan":"pro"}}]}'

# the same numbers as Studio: /overview, /trend?event=, POST /funnel {"steps":[...]}, /retention, /user?user_id=
SQL
select name, count(*) events, count(distinct uid) users
from _stitch_analytics.events where at > now() - interval '7 days'
group by name order by events desc;

#Limits

Each event counts toward the plan’s events per month. When they are used up, tracking answers 429 until the next month and the SDKs keep events on the device in the meantime, up to 1,000. Single events are kept for the plan’s days. Daily active users and event counts are kept 400 days. Funnels, breakdowns and retention read at most 90 days and stop after 20 seconds, so they never keep your database busy.