| name | activity-posthog |
| description | Configures PostHog as the event source for Autoplay by adding the browser snippet, calling posthog.identify() with product_id, and setting up the PostHog webhook destination. The PostHog session ID is the scoping key used throughout the Autoplay integration. Use when the user mentions PostHog, posthog-js, posthog.identify, product_id, or asks how to capture user events for Autoplay. |
| disable-model-invocation | true |
Activity Source — PostHog
Read autoplay-core first. The PostHog session_id is the session_id used
for all session scoping throughout your Autoplay integration.
Step 1 — Add the browser snippet
import posthog from 'posthog-js'
posthog.init('YOUR_AUTOPLAY_API_KEY', {
api_host: 'https://us.i.posthog.com',
person_profiles: 'identified_only',
session_idle_timeout_seconds: 120,
loaded: (posthog) => {
posthog.identify(posthog.get_distinct_id(), {
product_id: 'YOUR_PRODUCT_ID',
});
},
})
Step 2 — Identify on login (highly recommended)
Run this immediately after your login flow completes:
posthog.identify(user.id, {
product_id: 'YOUR_AUTOPLAY_PRODUCT_ID',
email: user.email,
})
Without identify, users are tracked anonymously. session_id still works for scoping; user_id and email will be None on ActionsPayload until identity is set.
Step 3 — Session ID in your backend
async def on_actions(payload):
if not payload.session_id:
return
await agent_writer.add(payload)
Step 4 — PostHog webhook destination
In PostHog, add a Webhook destination:
- Webhook URL:
result.webhook_url from onboard_product
X-PostHog-Secret header: result.webhook_secret from onboard_product
Or message #just-integrated in the Autoplay Slack for managed setup.
Step 5 — Verify the webhook is firing
After setting up the destination in PostHog, trigger a page event in your app
and check the PostHog destination logs (PostHog → Data pipelines → your webhook
destination → Logs). You should see a 200 response within a few seconds.
If you see 401:
- Check that
X-PostHog-Secret is copied verbatim (exact casing) — see Common mistakes below.
If you see no delivery at all:
- Confirm the destination is enabled and the filter is not excluding your events.
Common mistakes
X-PostHog-Secret header lookup is case-sensitive.
PostHog delivers the secret in inputs.headers["X-PostHog-Secret"] (exact casing).
Reading inputs.headers["x-posthog-secret"] or any other casing returns None
and your webhook handler will return 401 on every request. Always copy the key
name verbatim from the onboard_product response.
Reference