PostHog
Product analytics, session replay, feature flags, and more for React Native.
Introduction
Account Setup
Reverse Proxy Setup
We recommend setting up a reverse proxy when using PostHog. The idea is that various adblockers can intercept and block PostHog from sending events and other data to PostHog's servers. If that happens, you'll have no insight into those users.
The solution is setting up a reverse proxy, which is just a server that forwards the request to PostHog. So from the perspective of adblockers, it thinks it's just a regular HTTPS request to a regular domain, so it allows it through. From there, the reverse proxy sends the request to PostHog.
✅ You only need to set this up once, and you can use this reverse proxy for all of your apps. Just specify the same EXPO_PUBLIC_POSTHOG_HOST
.
There are a few ways to do this:
CloudFlare (Recommended)
Provided Code + Wrangler CLI
The steps to set up the reverse proxy are straightforward, but we've made it even easier for you! We've included the CloudFlare Worker code as part of the template, under apps/worker/posthog-proxy
.
All you have to do is:
Sign up for a Cloudflare account, if you don't already have one.
Run the following command to authenticate the Wrangler CLI (the official CLI tool for interacting with CloudFlare Workers) with your account:
cd apps/workers/posthog-proxy
npx wrangler login
Deploy the Worker code:
npx wrangler deploy
This will deploy the worker to <YOUR_WORKER>.<YOUR_SUBDOMAIN>.workers.dev
, as well as any custom domains. The CLI will tell you what the Worker domain is.
Update the PostHog host value in .env
to:
EXPO_PUBLIC_POSTHOG_HOST=<the domain of your worker>
You don't need to include "https://"
.
PostHog events should now be sent to your worker, which then sends it to PostHog! ✅
Manual
If would not like to use the provided reverse proxy CloudFlare Worker code, you can also set this up yourself!
Follow the steps here: https://posthog.com/docs/advanced/proxy/cloudflare
In short, you would have to:
Login/Signup for a CloudFlare account
Create a CloudFlare Worker (a few clicks)
Copy + paste the provided reverse proxy code
Make note of the domain of the worker. By default, it would be <some words>.workers.dev
. You can also use a custom domain, which is covered by their steps.
Then, update the .env
to:
EXPO_PUBLIC_POSTHOG_HOST=<the domain of your worker>
CloudFlare has an extremely generous free tier, meaning you can get 100,000 requests per day on the free plan. That's more than enough to get started.
Managed by PostHog
https://posthog.com/docs/advanced/proxy/managed-reverse-proxy
This is a service offered by PostHog themselves, however, you will need the Scale Add-On, which is very expensive. We recommend going with CloudFlare.
Installation
AppKickstarter already has PostHog installed and ready to go.
Dashboard Setup
To confirm everything is working, you should be able to see events: