---
title: "Deploy CAPI Relay for Facebook and Instagram Ads"
description: "Consent-first server-side Conversions API for your Pixel, GDPR-ready"
category: "Analytics"
url: https://railway.com/deploy/capi-relay-or-server-side-tracking-for-f
---

# Deploy CAPI Relay for Facebook and Instagram Ads

Consent-first server-side Conversions API for your Pixel, GDPR-ready

**[Deploy CAPI Relay for Facebook and Instagram Ads on Railway](https://railway.com/template/capi-relay-or-server-side-tracking-for-f)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/capi-relay-or-server-side-tracking-for-f/manifest.json

- **Creator:** jean82290
- **Category:** Analytics
- **Total deploys:** 1

## Template content

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

### CAPI Relay https://raw.githubusercontent.com/jean82290/capi-relay/main/assets/icon.svg

- **Source:** jean82290/capi-relay
- **Health check:** /healthz
- **Public domain:** Yes

## Documentation

# Deploy and Host CAPI Relay with Railway

CAPI Relay is an open-source, consent-first relay for the Meta Conversions API. Your website and backend send conversion events to it; it hashes customer data, deduplicates events against your browser Pixel with a shared event ID, and delivers them to Facebook and Instagram ads with automatic retries. Nothing is sent without consent.

## About Hosting CAPI Relay

The template deploys two services: the relay, a small Node.js app with a single dependency, and a Postgres database holding a short-lived delivery queue, connected over the private network. You paste your dataset (Pixel) ID and a Conversions API access token from Events Manager (no Meta app review needed) and list the websites allowed to send events. Railway generates the dashboard password and the API key. Then add a custom domain such as t.yourshop.com so the browser sends the Pixel's first-party cookies to the relay, add the two-line snippet to your site, connect it to your cookie banner, and watch deliveries in the built-in dashboard at /admin.

## Common Use Cases

- Recover purchases and leads the browser Pixel misses because of ad blockers, Safari tracking limits or closed tabs
- Send order confirmations and CRM lead updates from your backend straight to Meta with POST /v1/events
- Run server-side tracking for EU and UK websites with consent enforced and short data retention (GDPR)
- Replace a paid hosted tracking gateway with one service you own

## Dependencies for CAPI Relay Hosting

- PostgreSQL (included in this template)
- A Meta dataset (Pixel) ID and a Conversions API access token from Events Manager
- A cookie banner on your website that can run a JavaScript callback when marketing consent is given

### Deployment Dependencies

- Documentation: https://jean82290.github.io/capi-relay/
- Source code (MIT): https://github.com/jean82290/capi-relay
- Meta Conversions API: https://developers.facebook.com/docs/marketing-api/conversions-api
- Generate an access token: Events Manager > your dataset > Settings > Conversions API

### Implementation Details

```html
<script>
  window.capi = window.capi || function () { (capi.q = capi.q || []).push(arguments) };
</script>
<script async src="https://t.yourshop.com/capi.js"></script>
<script>
  // From your cookie banner, once marketing consent is given:
  capi('consent', true);
  // Instead of fbq('track', ...): fires the Pixel and the relay with the same event ID
  capi('track', 'Purchase', { value: 49.90, currency: 'EUR' });
</script>
```

Included: consent required by default, SHA-256 hashing following Meta's normalization rules, event ID deduplication, a Postgres queue with exponential backoff, automatic isolation of invalid events, 7-day data retention, a dashboard with delivery rate and Meta's error messages, and a test-event button.

Not affiliated with, endorsed or sponsored by Meta Platforms, Inc. You are responsible for collecting valid consent and following Meta's Business Tools Terms.

## Why Deploy CAPI Relay on Railway?

<!-- Recommended: Keep this section as shown below -->
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying CAPI Relay on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
<!-- End recommended section -->


## Similar templates

- [Plausible WordPress](https://railway.com/deploy/deploy-plausible-for-wordpress-sites) — Cookie-free WordPress stats from your own Plausible
- [Typesense Multilingual](https://railway.com/deploy/deploy-typesense-multilingual-search) — Locale-aware multilingual search with Typesense
- [Formbricks](https://railway.com/deploy/formbricks-surveys) — Surveys, NPS and in-app feedback on your own Postgres, Hub and Cube

Open this page in a browser: https://railway.com/deploy/capi-relay-or-server-side-tracking-for-f
