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

/var/lib/postgresql/data

Just deployed

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

Implementation Details

<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?

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.


Template Content

More templates in this category

View Template
NEW
Plausible WordPress
Cookie-free WordPress stats from your own Plausible

onepush
0
View Template
Typesense Multilingual
Locale-aware multilingual search with Typesense

onepush
0
View Template
Formbricks
Surveys, NPS and in-app feedback on your own Postgres, Hub and Cube

Two Workspaces
3