Typeform to PostHog Webhook

A REST API endpoint that receives Typeform webhook submissions and forwards them as events to PostHog.

Setup

  1. Set the POSTHOG_API_KEY environment variable in your Val Town settings with your PostHog API key.

Endpoints

POST /typeform-submit

Accepts Typeform webhook payloads and sends a typeform_completed event to PostHog.

Request Body:

{ "form_response": { "form_id": "form_123", "token": "response_456", "submitted_at": "2024-01-01T12:00:00Z", "landed_at": "2024-01-01T11:55:00Z", "hidden": { "user_id": "user_789", "source": "email_campaign" } } }

Response:

  • 200 OK: Event successfully sent to PostHog
  • 500 Internal Server Error: Missing API key or PostHog API error

GET /

Health check endpoint that returns API information.

PostHog Event Structure

The endpoint sends events to PostHog with the following structure:

  • Event Name: typeform_completed
  • Distinct ID: Uses hidden.user_id, falls back to landed_at, then 'anonymous'
  • Properties: Includes all hidden fields plus:
    • form_id: Typeform form identifier
    • response_id: Typeform response token
    • submitted_at: Submission timestamp

Typeform Webhook Configuration

In your Typeform settings:

  1. Go to Connect → Webhooks
  2. Add webhook URL: https://your-val-url.web.val.run/typeform-submit
  3. Select "Form submitted" trigger
  4. Configure any hidden fields you want to pass through to PostHog

Environment Variables

  • POSTHOG_API_KEY: Your PostHog project API key (required)