Marketing · n8n

Trigger Customer.io Campaigns Instantly from PostHog User Events

Automatically enroll users into Customer.io campaigns the moment they fire a key event in PostHog. Stop missing conversion windows by connecting your product analytics directly to your marketing automation.

difficulty Intermediatesetup 45 minresult When a target PostHog event fires, the user is immediately identified and enrolled in the matching Customer.io campaign without any manual work.
  1. 1

    Receive PostHog Event via Webhook

    Add a Webhook node as the trigger. In PostHog, go to Project Settings > Webhooks and paste the n8n webhook URL. Set the PostHog webhook to fire on the specific action you care about (e.g. signed_up or trial_started). In n8n the node listens at the path /posthog-event. Set HTTP Method to POST and note the production URL.

  2. 2

    Extract and Validate Event Data

    Add a Set node named Extract Event Data. Map these fields from the incoming webhook body: set email to {{ $json.body.person.properties.email }}, userId to {{ $json.body.person.distinct_id }}, and eventName to {{ $json.body.event }}. This normalises the PostHog payload into clean variables for the next steps.

  3. 3

    Filter for the Target Event

    Add an IF node named Is Target Event. Set the condition: {{ $json.eventName }} equals the exact PostHog event name you want to act on, for example trial_started. The TRUE branch continues to Customer.io. The FALSE branch can be left unconnected to silently drop unmatched events.

  4. 4

    Identify or Update the Person in Customer.io

    Add an HTTP Request node named Upsert Person in Customer.io. Set Method to PUT and URL to https://track.customer.io/api/v1/customers/{{ $json.userId }}. Under Authentication choose Header Auth and add header Authorization with value Basic YOUR_SITE_ID:YOUR_API_KEY (base64-encoded). Set Body Content Type to JSON and pass { "email": "{{ $json.email }}", "posthog_event": "{{ $json.eventName }}" }. This creates or updates the person so Customer.io can match them to a campaign. Store your credentials in n8n Credentials, not plain text.

  5. 5

    Fire the Customer.io Campaign Trigger Event

    Add a second HTTP Request node named Send Campaign Event. Set Method to POST and URL to https://track.customer.io/api/v1/customers/{{ $json.userId }}/events. Use the same Basic auth header as the previous node. Set the JSON body to { "name": "{{ $json.eventName }}", "data": { "source": "posthog" } }. In Customer.io, create a campaign with the trigger set to this exact event name. The campaign will now fire automatically every time PostHog sends the matching event.

Frequently asked questions

How do I find my Customer.io Site ID and API Key?

Log in to Customer.io, go to Settings > Account > API Credentials. Your Site ID and Tracking API Key are listed there. Base64-encode the string `siteId:apiKey` and use it as the Basic auth header value.

Can I trigger this for multiple PostHog events?

Yes. Either add more conditions to the IF node using OR logic, or duplicate the entire workflow for each event and change the event name in the filter. Using separate workflows keeps things easier to debug.

What if PostHog does not send the user's email in the webhook?

Make sure you call `posthog.identify()` in your product with the user's email as a property before the event fires. PostHog webhooks include person properties only when the person has been identified. You can also enrich the payload by calling the PostHog Persons API inside n8n using an extra HTTP Request node.

About this recipe. Recipes on FlowRecipesHub are written for business owners, not developers, and are tested before publishing — how recipes get made. Some ingredient links are affiliate links that cost you nothing — full disclosure.