> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tryproduck.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PostHog webhook

> Arm a campaign trigger for the users your PostHog events name.

A trigger normally offers its interview to every visitor who reaches the moment it fires on. With
the PostHog webhook, an event from your backend or your PostHog pipeline first **arms** the trigger
for one user, and only an armed user is offered it. The offer itself still fires from the page's own
PostHog event, as [event triggers](https://docs.tryproduck.com/sdk/javascript-api.md#event-triggers) do, so it lands at the moment
and not seconds later when the webhook arrives.

An arm is used up by the first offer, lives for the days you set, and can be taken back by a
disarming event. Arms are keyed by PostHog distinct id, so the page must have posthog-js loaded and
must identify the user with the same distinct id your server events use.

## Get the URL

In the dashboard, open **Settings › Integrations** and press **Connect** on the PostHog card. The
sheet shows your full **webhook URL** once: copy it before you close the sheet. The URL is the only
credential; PostHog sends no header for it.

## Create the destination in PostHog

In PostHog, go to **Data pipelines › New destination › HTTP Webhook** and set:

| Setting | Value |
| - | - |
| URL | The webhook URL from the sheet. |
| Method | `POST` |
| Headers | Leave PostHog's defaults as they are. |
| Body | Leave PostHog's default body as it is. |
| Filters | Only the arming and disarming events your triggers use. |

PostHog bills every event a destination sends, so keep the filters to the events your triggers arm
and disarm on. One destination per event, each with its own filters, keeps the volume lowest.

## Set the trigger

On the campaign's **Triggers** tab, open the trigger and turn on **Only for armed users**:

* **Arming event** — the event, with any property filters, that arms the user for the trigger.
* **Disarming event** — optional; an event that takes the arm back, with its own filters.
* **Days** — how long an arm lives, 1 to 30. An arm not used within that time expires.

A trigger with this on is never offered to a user who has no live arm, and never to the same user
twice.

## Worked example

A product sends two kinds of email and wants an interview only from the users who got one, at the
moment the email was about, plus a first-lesson interview from new sign-ups in one country who have
not finished a lesson in the app yet. Each row is one HTTP Webhook destination in PostHog, all with
the same URL.

| Destination filter | Trigger setting |
| - | - |
| `campaign_sent` where `campaign` is one of the welcome-back email names | Welcome back: fires on `plan_ready`; **Only for armed users** on, armed by `campaign_sent` with `campaign` is one of the welcome-back names; 14 days |
| `campaign_sent` where `campaign` is one of the progress email names | Progress: fires on `lesson_completed`; armed by `campaign_sent` with `campaign` is one of the progress names; 14 days |
| `user created` where `country` is `KR` | First lesson: fires on `lesson_completed`; armed by `user created` with `country` is `KR`; disarmed by `lesson_completed`; 30 days |
| `lesson_completed` where person `$geoip_country_code` is `KR` | The first-lesson disarm, so a lesson finished in a mobile app also counts |

The web page captures `plan_ready` and `lesson_completed` through posthog-js under the user's id, so
the offer fires there; the server captures `campaign_sent` and `user created` under the same id, so
the webhook arms the right user.

## Regenerate the URL

Open **Settings › Integrations › Manage** and press **Regenerate URL**. The current URL stops
working at once, so update every destination's URL in PostHog with the new one straight away.
Events PostHog sends to the old URL in the meantime are refused with `404`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.