Using Vercel rewrites as a reverse proxy

Last updated:

|Edit this page

Vercel supports rewrites which we can use as a reverse proxy. Create a vercel.json file and add a rewrites object from the /ingest route to https://app.posthog.com or https://eu.posthog.com.

JSON
{
"rewrites": [
{
"source": "/ingest/:match*",
"destination": "https://app.posthog.com/:match*"
}
]
}

Once done, set the /ingest route of your domain as the API host in your PostHog initialization like this:

JavaScript
posthog.init('<ph_project_api_key>',
{
api_host: 'https://www.your-domain.com/ingest',
}
)

Once updated, deploy your changes on Vercel and check that PostHog requests are going to https://www.your-domain.com/ingest by checking the network tab on your domain.

Setup video

Questions?

Was this page useful?

Next article

Product analytics for browser extensions

Do you have a Firefox or Chrome browser plugin with a user interface and want to understand how it's being used? PostHog is the perfect way to do just that. Setup for Firefox & Chrome plugins Installing PostHog inside your plugin Open the HTML file used in your default_popup and add the PostHog array.js script. To do this you'll need to either: Copy the latest version of array.js from: https://app.posthog.com/static/array.js and import it locally using <script src="array.js" /> before…

Read next article