Note: If you are using the EU cloud then use
eu
instead ofus
in all domains (e.g.us.i.posthog.com
->eu.i.posthog.com
)
Netlify supports redirects and rewrites which we can use as a reverse proxy from an /ingest
route. In your netlify.toml
file, add a redirect like this:
[[redirects]]from = "/ingest/static/*"to = "https://us-assets.i.posthog.com/static/:splat"host = "us-assets.i.posthog.com"status = 200force = true[[redirects]]from = "/ingest/*"to = "https://us.i.posthog.com/:splat"host = "us.i.posthog.com"status = 200force = true
Once done, set the /ingest
route of your domain as the API host in your PostHog initialization like this:
posthog.init('<ph_project_api_key>',{api_host: 'https://www.your-domain.com/ingest',ui_host: '<ph_app_host>'})
Once updated, deploy your changes on Netlify and check that PostHog requests are going to https://www.your-domain.com/ingest
by checking the network tab on your domain.