Skip to main content

Documentation Index

Fetch the complete documentation index at: https://developers.autoplay.ai/llms.txt

Use this file to discover all available pages before exploring further.

Auto-generated from autoplay_sdk/skills/. Edit the source SKILL.md and run python scripts/sync_skill_docs.py.
Download .md ยท Open raw file ยท Install via CLI: autoplay-install-skills

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',
        });
    },
})

Run this immediately after your login flow completes:
posthog.identify(user.id, {
    product_id: 'YOUR_AUTOPLAY_PRODUCT_ID',
    email: user.email,  // optional but enables email-based session scoping
})
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

# The session_id on every ActionsPayload is the PostHog session ID
# Retrieve it in browser:
#   posthog.get_distinct_id()   โ€” stable user/device ID
#   posthog.get_session_id()    โ€” current session ID (resets on idle)

# Guard for None before identity linking:
async def on_actions(payload):
    if not payload.session_id:
        return   # anonymous pre-identity event โ€” skip or queue
    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