Are Analytics Drains always project-wide, or can they be configured to only send events for a specific environment? What is the recommended approach if we want to ingest only production analytics data into our production environment and dev/preview data into our dev environment?
Are you resending the web analytics data if the endpoint you are sending the events to responds with a code not equal to 200?
Analytics Drains are project-scoped, not environment-scoped. When configuring a Web Analytics Drain, you can only select which projects should send data to your endpoint. There’s no native option to filter by environment (production vs. preview/development) for Web Analytics drains.
However, each analytics event does include a vercelEnvironment field (with values like "production") in the payload, so you can filter events on the receiving end.
Since you can’t configure environment-level filtering at the drain level for Web Analytics, the recommended approaches are:
Filter at your ingestion endpoint: Configure a single drain and have your receiving endpoint inspect the vercelEnvironment field in each event, routing production events to your production analytics store and dev/preview events elsewhere.
Use a middleware/proxy: Set up an intermediary endpoint that receives all events and routes them to different backends based on the vercelEnvironment value.
Use sampling + filtering: If you primarily care about production data, set a low sampling rate and filter by environment at ingestion time.