PostHog Webhook Integration
The PostHog Webhook Integration allows you to seamlessly ingest product analytics events from your PostHog project directly into your OpenCDP workspace. By configuring a webhook in PostHog, OpenCDP can automatically sync user identities, device registrations, and custom tracking events in real time.
Overview
The integration exposes a dedicated data gateway endpoint:
POST /data-gateway/v1/posthog
This endpoint processes incoming webhook payloads from PostHog and maps them to OpenCDP's internal data structures:
$identifyevents: Creates or updates user profiles in OpenCDP.$register_deviceevents: Registers user devices (e.g., for push notifications).- Custom track events: Records user activities and behaviors, preserving PostHog-specific metadata.
Prerequisites
Before setting up the integration, ensure you have:
- An active OpenCDP Workspace.
- A valid OpenCDP API Key (used to authenticate requests from PostHog).
- A PostHog Project with access to configure Data Pipelines or Webhook destinations.
Endpoint & Authentication
- Webhook URL:
https://api.opencdp.io/gateway/data-gateway/v1/posthog - Method:
POST - Authentication: You must provide your OpenCDP API Key in the
AuthorizationHTTP header.
Required Header
Authorization: <YOUR_OPEN_CDP_API_KEY>
Payload Requirements
The OpenCDP webhook expects the standard JSON payload format generated by PostHog. At a minimum, the payload must contain an event object.
{
"event": {
"event": "event_name",
"properties": { ... },
"distinct_id": "user_123",
"uuid": "...",
"timestamp": "2023-10-01T12:00:00Z"
}
}
Event Mapping Behavior
1. Identifying Users ($identify)
When PostHog sends an $identify event, OpenCDP captures the user's details and updates their profile.
- Trigger: PostHog event named
$identify. - Identifier: OpenCDP looks for the user's ID in
event.properties.idfirst. If missing, it falls back toevent.distinct_id. - Properties: All properties sent inside
event.propertiesare attached to the identified user in OpenCDP.
2. Registering Devices ($register_device)
To track mobile devices (e.g., for push campaigns), you can send a $register_device event from PostHog.
- Trigger: PostHog event named
$register_device. - Required Properties: The event properties must include:
device_id: A unique identifier for the device.platform: The device platform (e.g.,ios,android,web).fcm_token: The Firebase Cloud Messaging token for push notifications.
- Optional Properties: You can also include
name,os_version,model,apn_token,app_version,last_active_at, and anattributesobject containing further device metadata.
Example Device Registration Payload:
{
"event": {
"event": "$register_device",
"distinct_id": "user_123",
"properties": {
"device_id": "device_abc_123",
"platform": "ios",
"fcm_token": "fcm_xyz_987",
"os_version": "17.0",
"app_version": "1.2.0"
}
}
}
3. Custom Tracking Events
All other events that are not $identify or $register_device are processed as standard Track events.
- Trigger: Any event name other than the predefined ones.
- Loop Prevention: Events where the identifier contains the word
"posthog"(case-insensitive) are ignored to prevent recursive loops or handling internal PostHog system users. - Metadata Context: OpenCDP automatically captures the event properties and nests PostHog-specific metadata (
uuid,distinct_id,url,timestamp) inside aposthogproperty within the Track event payload.
Setup Instructions in PostHog
To start sending data from PostHog to OpenCDP:
- Log in to your PostHog dashboard.
- Navigate to Data Pipeline > Destinations (or Webhooks).
- Create a new Destination and choose the Webhook option.
- Set the Webhook URL to your OpenCDP endpoint:
https://api.opencdp.io/gateway/data-gateway/v1/posthog - In the headers configuration section, add a new header:
- Key:
Authorization - Value:
<YOUR_OPEN_CDP_API_KEY>
- Key:
- Configure the destination to trigger on all events, or filter for specific events like
$identifyand$register_device. - Save and enable the webhook.
Troubleshooting
- 401 Unauthorized: Ensure your OpenCDP API key is valid, unexpired, and correctly placed in the
Authorizationheader. - 400 Bad Request / Validation Error: Verify that your PostHog payload contains the
eventroot object and an identifier (distinct_idorid). If registering a device, ensure all required properties (device_id,platform,fcm_token) are present. - Events Not Appearing: Check if the identifier in PostHog contains the word
"posthog". OpenCDP deliberately ignores identifiers containing"posthog"to prevent infinite loops.