LogoLogo
  • Contributing to RudderStack
  • Destination_Name
  • LICENSE
  • RudderStack Docs
  • docs
    • FAQ
    • Identity Resolution
    • Home
    • cloud-extract-sources
      • ActiveCampaign Source
      • Bing Ads
      • Chargebee
      • Common Settings
      • Facebook Ads
      • Freshdesk
      • Google Ads Source
      • Google Analytics
      • Google Search Console
      • Google Sheets
      • Cloud Extract Sources
      • Intercom v2
      • Intercom
      • Mailchimp
      • Marketo
      • Mixpanel
      • NetSuite
      • Pipedrive
      • QuickBooks
      • Salesforce Pardot
      • Sendgrid Source
      • Stripe Source
      • Xero
      • Zendesk Chat
      • Zendesk
      • hubspot
        • HubSpot Data Model and Schema Information
        • HubSpot
      • salesforce
        • Salesforce
        • Schema Comparison: RudderStack vs. Segment
    • connections
      • Connection Modes: Cloud Mode vs. Device Mode
    • data-governance
      • Data Governance
      • RudderTyper
      • Data Governance API
      • RudderTyper
      • tracking-plans
        • Tracking Plans
        • Tracking Plan Spreadsheet
    • data-warehouse-integrations
      • Amazon Redshift
      • Azure Data Lake
      • Azure Synapse
      • ClickHouse
      • Databricks Delta Lake
      • Google Cloud Storage Data Lake
      • Google BigQuery
      • Identity Resolution
      • Warehouse Destinations
      • Microsoft SQL Server
      • PostgreSQL
      • Amazon S3 Data Lake
      • Snowflake
      • FAQ
      • Warehouse Schema
    • destinations
      • Destinations
      • Webhooks
      • advertising
        • Bing Ads
        • Criteo
        • DCM Floodlight
        • Facebook App Events
        • Facebook Custom Audience
        • Facebook Pixel
        • Google Ads (gtag.js)
        • Google AdWords Enhanced Conversions
        • Google Adwords Remarketing Lists (Customer Match)
        • Advertising
        • LinkedIn Insight Tag
        • Lotame
        • Pinterest Tag
        • Reddit Pixel
        • Snap Pixel
        • TikTok Ads
      • analytics
        • Amplitude
        • AWS Personalize
        • Chartbeat
        • Firebase
        • FullStory
        • Google Analytics 360
        • Google Analytics
        • Heap.io
        • Hotjar
        • Analytics
        • Indicative
        • Keen
        • Kissmetrics
        • Kubit
        • Lytics
        • Mixpanel
        • Pendo
        • PostHog
        • Quantum Metric
        • Singular
        • adobe-analytics
          • Adobe Analytics Heartbeat Measurement
          • Mobile Device Mode Settings
          • Web Device Mode Settings
          • E-commerce Events
          • Adobe Analytics
          • Setting Up Adobe Analytics in RudderStack
        • google-analytics-4
          • Cloud Mode
          • Device Mode
          • Google Analytics 4
          • Setting up Google Analytics 4
        • profitwell
          • ProfitWell
          • Cloud Mode
          • Device Mode
      • attribution
        • Adjust
        • AppsFlyer
        • Branch
        • Attribution
        • Kochava
        • TVSquared
      • business-messaging
        • Business Messaging
        • Intercom
        • Kustomer
        • Slack
        • Trengo
      • continuous-integration
        • Visual Studio App Center
        • Continuous Integration
      • crm
        • Delighted
        • HubSpot
        • CRM
        • Salesforce
        • Variance
        • Zendesk
      • customer-data-platform
        • Customer Data Platform
        • Segment
      • error-reporting
        • Bugsnag
        • Error Reporting
        • Sentry
      • marketing
        • ActiveCampaign
        • AdRoll
        • Airship
        • Appcues
        • Autopilot
        • Blueshift
        • Braze
        • CleverTap
        • Customer.io
        • Gainsight PX
        • Gainsight
        • Marketing
        • Iterable
        • Klaviyo
        • Leanplum
        • Mailchimp
        • Marketo Lead Import
        • Marketo
        • MoEngage
        • Ometria
        • Pardot
        • Post Affiliate Pro
        • Qualtrics
        • SendGrid
        • Salesforce Marketing Cloud
        • Userlist
        • drip
          • Cloud Mode
          • Device Mode
          • Drip
          • Setting Up Drip in RudderStack
      • productivity
        • Google Sheets
        • Productivity
      • storage-platforms
        • Amazon S3
        • DigitalOcean Spaces
        • Google Cloud Storage
        • Storage Platforms
        • Azure Blob Storage
        • MinIO
        • Redis
      • streaming-platforms
        • Amazon EventBridge
        • Amazon Kinesis Firehose
        • Amazon Kinesis
        • Azure Event Hubs
        • BigQuery Stream
        • Confluent Cloud
        • Google Pub/Sub
        • Streaming Platforms
        • Apache Kafka
      • tag-managers
        • Google Tag Manager
        • Tag Managers
      • testing-and-personalization
        • Algolia Insights
        • Candu
        • Google Optimize
        • A/B Testing & Personalization
        • LaunchDarkly
        • Monetate
        • Optimizely Full Stack
        • Optimizely Web
        • Split.io
        • Statsig
        • VWO (Visual Website Optimizer)
    • get-started
      • RudderStack Cloud vs. RudderStack Open Source
      • Glossary
      • Get Started
      • RudderStack Architecture
    • reverse-etl
      • Amazon Redshift
      • Amazon S3
      • ClickHouse
      • FAQ
      • Google BigQuery
      • Reverse ETL
      • PostgreSQL
      • Snowflake
      • common-settings
        • Importing Data using Models
        • Importing Data using Tables
        • Common Settings
        • Sync Modes
        • Sync Schedule
      • features
        • Airflow Provider
        • Features
        • Models
        • Visual Data Mapper
    • rudderstack-api
      • Data Regulation API
      • HTTP API
      • RudderStack API
      • Personal Access Tokens
      • Pixel API
      • Test API
      • api-specification
        • Application Lifecycle Events Specification
        • API Specification
        • Video Events Specification
        • rudderstack-ecommerce-events-specification
          • Browsing
          • Coupons
          • E-Commerce Events Specification
          • Ordering
          • Promotions
          • Reviewing
          • Sharing
          • Wishlist
        • rudderstack-spec
          • Alias
          • Common Fields
          • Group
          • Identify
          • RudderStack Event Specification
          • Page
          • Screen
          • Track
    • rudderstack-cloud
      • Audit Logs
      • Dashboard Overview
      • Destinations
      • RudderStack Cloud
      • Live Events
      • Connection Modes: Cloud Mode vs. Device Mode
      • Sources
      • Teammates (User Management)
      • connections
        • Adding a Destination
        • Connections
    • rudderstack-open-source
      • Control Plane Setup
      • RudderStack Open Source
      • installing-and-setting-up-rudderstack
        • Developer Machine Setup
        • Docker
        • Data Plane Setup
        • Kubernetes
        • Sending Test Events
    • stream-sources
      • App Center
      • AppsFlyer
      • Auth0
      • Braze
      • Customer.io
      • Extole
      • Event Stream Sources
      • Iterable
      • Looker
      • PostHog
      • Segment
      • Shopify
      • Webhook Source
      • rudderstack-sdk-integration-guides
        • Client-side Event Filtering
        • SDKs
        • AMP Analytics
        • Cordova
        • .NET
        • Go
        • Java
        • Node.js
        • PHP
        • Python
        • React Native
        • Ruby
        • Rust
        • Unity
        • SDK FAQs
        • rudderstack-android-sdk
          • Adding Application Class
          • Flushing Events Periodically
          • Android
        • rudderstack-flutter-sdk
          • Flutter SDK v1
          • Flutter v2
          • Flutter
        • rudderstack-ios-sdk
          • iOS
          • tvOS
          • watchOS
        • rudderstack-javascript-sdk
          • Data Storage in Cookies
          • Detecting Ad-blocked Pages
          • JavaScript
          • JavaScript SDK Enhancements
          • JavaScript SDK FAQs
          • Querystring API
          • Quick Start Guide
          • Version Migration Guide
          • consent-managers
            • Consent Managers
            • OneTrust
    • transformations
      • Access Token
      • FAQ
      • Transformations
      • Transformations API
    • user-guides
      • User Guides
      • administrators-guide
        • Troubleshooting Guide
        • Alerting Guide
        • Bucket Configuration Settings for Event Backups
        • Configuration Parameters
        • Event Replay
        • High Availability
        • Horizontal Scaling
        • Administrator's Guides
        • Infrastructure Provisioning
        • Monitoring and Metrics
        • Okta SSO Setup
        • OneLogin SSO Setup
        • RudderStack Grafana Dashboard
        • Software Releases
      • how-to-guides
        • How to Use Custom Domains
        • How to Develop Integrations for RudderStack
        • How to Configure a Destination via the Event Payload
        • How to Filter Events using Different Methods
        • How to Filter Selective Destinations
        • How to Submit a Pull Request for a New Integration
        • How-to Guides
        • How to Debug Live Destination Events
        • How to Use AWS Lambda Functions with RudderStack
        • create-a-new-destination-transformer-for-rudder
          • Best Practices for Coding Transformation Functions in JavaScript
          • How to Create a New Destination Transformation for RudderStack
        • implement-native-js-sdk-integration
          • How to Add a Device Mode SDK to RudderStack JavaScript SDK
          • How to Implement a Native JavaScript SDK Integration
        • rudderstack-jamstack-integration
          • How to Integrate RudderStack with Your JAMstack Site
          • How to Integrate Rudderstack with Your Angular App
          • How to Integrate Rudderstack with Your Astro Site
          • How to Integrate Rudderstack with Your Eleventy Site
          • How to Integrate Rudderstack with Your Ember.js App
          • How to Integrate Rudderstack with a Gatsby Website
          • How to Integrate Rudderstack with a Hugo Site
          • How to Integrate Rudderstack with Your Jekyll Site
          • How to Integrate Rudderstack with Your Next.js App
          • How to Integrate Rudderstack with Your Nuxt.js App
          • How to Integrate Rudderstack with Your Svelte App
          • How to Integrate Rudderstack with Your Vue App
      • migration-guides
        • Migrating from Blendo to RudderStack
        • Migrating Your Warehouse Destination from Segment to RudderStack
        • Migration Guides
        • Migrating from Segment to RudderStack
  • src
    • @rocketseat
      • gatsby-theme-docs
        • text
          • Home
Powered by GitBook
On this page
  • Getting started
  • Connection settings
  • Web SDK settings
  • Identify
  • Page
  • Screen
  • Track
  • Group
  • Updated group mapping
  • Alias
  • Passing super properties in the PostHog web SDK
  • Property mapping
  • FAQs
  • How do I obtain the PostHog Team API Key?
  • Contact us

Was this helpful?

  1. docs
  2. destinations
  3. analytics

PostHog

Step-by-step guide to send event data from RudderStack to PostHog.

PreviousPendoNextQuantum Metric

Last updated 3 years ago

Was this helpful?

is a complete product analytics stack built for data analysts and managers. It gives you easy access to scalable product analytics with full control over all your user data.

RudderStack supports PostHog as a destination to which you can seamlessly send your event data for analytics.

Find the open-source transformer code for this destination in our .

Getting started

Before configuring PostHog as a destination in RudderStack, verify if the source platform is supported by PostHog by referring to the table below:

Connection Mode

Web

Mobile

Server

Device Mode

Supported

-

-

Cloud Mode

Supported

Supported

Supported

To know more about the difference between cloud mode and device mode in RudderStack, refer to the guide.

Once you have confirmed that the source platform supports sending events to PostHog, follow these steps:

  1. From your , add the source. Then, from the list of destinations, select PostHog.

  2. Assign a name to your destination and click on Next.

Connection settings

To successfully configure PostHog as a destination, you will need to configure the following settings:

  • Team API Key: Enter your PostHog team API key. This is a mandatory field.

The settings are listed below:

  • Instance URL: Enter your PostHog instance URL.

If you’re hosting your own PostHog instance, add the URL of your instance without the trailing slash. So, the URL will look something like https://[your-instance].com.

  • Use updated mapping for Group calls: Enable this setting to send the group traits as event properties to PostHog.

Web SDK settings

This section lists some of the other configurable settings when sending events to PostHog via the web device mode.

  • Enable Local Storage for Persistence: Enable this option to reduce the amount of data stored in the cookies by storing it locally instead.

  • Allow PostHog to automatically capture pageview events: Enable this setting to allow the PostHog web SDK to send a page view event every time it is loaded on a page.

  • Disable session recoding: Enable this setting to stop PostHog from recording the user sessions.

  • Additional headers to pass with XHR requests to PostHog API: Add a list of key-value pairs in this field. The RudderStack web SDK will then forward these headers on the event requests sent to PostHog.

  • Property black list - Add a list of traits or event properties that you want the PostHog SDK to filter.

Identify

To identify a user in PostHog, you need to call RudderStack's identify API.

A sample identify call is as shown below:

rudderanalytics.identify("1hKOmRA4el9Zt1WSfVJIVo4GRlm", {
  name: "Alex Keener",
  first_name: "Alex",
  last_name: "Keener",
  email: "alex@example.com",
  createdAt: "2019-07-23T23:45:56.000Z",
})

Page

The page call lets you record your app's page views with any additional relevant information about the viewed page.

A sample page call is shown below:

rudderanalytics.page({
  path: "/best-seller/1",
  url: "https://www.estore.com/best-seller/1",
  title: "EStore Bestsellers",
  search: "estore bestseller",
  referrer: "https://www.google.com/search?q=estore+bestseller",
})

In the above example, RudderStack captures information related to the viewed page such as its path, URL, referrer, etc.

Screen

The screen call lets you record whenever your user views their mobile screen with any additional relevant information about the screen.

A sample screen call using RudderStack's iOS SDK is shown below:

[[RudderClient sharedInstance] screen:@"Home Screen"
            properties:@{@"category" : @"launcher"}];

In the above snippet, RudderStack captures information related to the viewed screen such as its name and category.

Track

The track call lets you capture user events along with the properties associated with them.

A sample track call is shown below:

rudderanalytics.track("Order Completed", {
  checkout_id: "C324532",
  order_id: "T1230",
  value: 15.98,
  revenue: 16.98,
  shipping: 3.0,
  coupon: "FY21",
  currency: "INR",
  products: [
    {
      product_id: "product-mixedfruit-jam",
      sku: "sku-1",
      category: "Food",
      name: "Food/Drink",
      brand: "Sample",
      variant: "None",
      price: 10.0,
      quantity: 2,
      currency: "INR",
      position: 1,
      value: 6.0,
      typeOfProduct: "Food",
      url: "https://www.example.com/product/bacon-jam",
      image_url: "https://www.example.com/product/bacon-jam.jpg",
    },
  ],
})

Group

The group call lets you associate a particular identified user with a group, such as a company, organization, or an account.

A sample group call is shown below:

rudderanalytics.group("sample_group_id", {
  name: "CompanyA",
  location: "USA",
})

Updated group mapping

RudderStack lets you use the updated mapping feature for the group calls where it maps the group traits as event properties before sending them to PostHog. To use this feature, enable the Use Updated Mapping for Group calls setting in the RudderStack dashboard, as shown:

When disabled (default), RudderStack sends the group traits to PostHog as received without any modifications, as shown in the following snippet:

{
  "version": "1",
  "type": "REST",
  "method": "POST",
  "endpoint": "https://app.posthog.com/batch",
  "headers": {
    "Content-Type": "application/json"
  },
  "params": {},
  "body": {
    "JSON": {
      "groupId": "groupId27",
      "distinct_id": "sampleusrRudder7",
      "traits": {
        "groupType": "company",
        "KEY_3": {
          "CHILD_KEY_92": "value_95",
          "CHILD_KEY_102": "value_103"
        },
        "name_trait": "Company",
        "value_trait": "Company-ABC"
      },
      "messageId": "e5034df0-a404-47b4-a463-76df99934fea",
      "event": "$group",
      "api_key": "LNDs0JGdwbknNGolFc4HdoAE",
      "type": "group"
    },
  },
}

When enabled, RudderStack sends the group traits as event properties to PostHog, as shown:

{
  "version": "1",
  "type": "REST",
  "method": "POST",
  "endpoint": "https://app.posthog.com/batch",
  "headers": {
    "Content-Type": "application/json"
  },
  "params": {},
  "body": {
    "JSON": {
      "distinct_id": "sampleusrRudder7",
      "messageId": "e5034df0-a404-47b4-a463-76df99934fea",
      "properties": {
        "$group_key": "groupId27",
        "$group_type": "company",
        "$group_set": {
          "KEY_3": {
            "CHILD_KEY_92": "value_95",
            "CHILD_KEY_102": "value_103"
          },
          "name_trait": "Company",
          "value_trait": "Comapny-ABC"
        },
      },
      "event": "$group",
      "api_key": "LNDs0JGdwbknNGolFc4HdoAE",
      "type": "group"
    },
  },
}

The mapping is as shown:

Group trait
Updated group mapping disabled
Updated group mapping enabled

groupId

groupId

$group_key

groupType

groupType

$group_type

traits

traits

$group_set

Alias

Calling alias() passes userId and previousId to the PostHog queue.

A sample alias call in RudderStack is as shown:

rudderanalytics.alias("user01", "previous01")

In the above example, previous01 gets mapped to distinct id in PostHog, while user01 gets mapped to alias in PostHog.

Passing super properties in the PostHog web SDK

  • The following example will set superKey1: "value1", superKey2: "value2" as super properties to the PostHog web SDK:

rudderanalytics.track("event", {prop: "value"}, {
  integrations: {
    POSTHOG: {
      superProperties: {
        superKey1: "value1",
        superKey2: "value2"
      }
    }
  }
})
  • The following example will set superKey3: "value3" as super properties just once and pass on to the PostHog web SDK:

// This will set {superKey3: "value3"} as set once super properties to PostHog SDK
rudderanalytics.track("event", {prop: "value"}, {
  integrations: {
    POSTHOG: {
      setOnceProperties: {
        superKey3: "value3"
      }
    }
  }
})
  • The following example unsets the previously set super properties:

// This will unset super properties superKey1, superKey2, superKey3 to PostHog SDK
rudderanalytics.track("event", {prop: "value"}, {
  integrations: {
    POSTHOG: {
      unsetProperties: [
        superKey1,
        superKey2,
        superKey3
      ]
    }
  }
})

The super properties can be passed to any of track, page, or identify calls of the RudderStack JavaScript SDK.

Property mapping

RudderStack maps the following properties sent to the Posthog standard contextual properties:

RudderStack field
PostHog field

context.os.name

$os

context.page.url

$current_url

url

$host

context.page.path

$pathname

context.screen.height

$screen_height

context.screen.width

$screen_width

context.library.name

$lib

context.library.version

$lib_version

originalTimestamp,timestamp

$time

context.device.id

$device_id

request_ip,context.ip

$ip

timestamp,originalTimestamp

$timestamp

anonymousId

$anon_distinct_id

userId,anonymousId

distinct_id

context.screen.density

$screen_density

context.device.manufacturer

$device_manufacturer

context.os.version

$os_version

context.timezone

$timezone

context.locale

$locale

context.userAgent

$user_agent

context.app.version

$app_version

context.device.name

$device_name

context.network.carrier

$network_carrier

context.app.name

$app_name

context.device.model

$device_model

context.app.namespace

$app_namespace

context.app.build

$app_build

The PostHog SDK autogenerates the property $insert_id when you send event via the RudderStack device mode. However, when sending the events via the cloud mode, RudderStack does not map any value to this property.

FAQs

How do I obtain the PostHog Team API Key?

To get your PostHog Project API Key or Team API Key, follow the steps below:

  1. Login to your PostHog dashboard.

  2. Go to the Settings tab under the Project section in the left sidebar.

  3. Find your key under Project API Key or Team API Key.

Contact us

For more information on obtaining your PostHog Team API Key, refer to the section below.

For more information, refer to the section below.

Use device mode to send events: If enabled, RudderStack will send the events to PostHog via the .

Enable autocapture with PostHog: Enable this option to allow PostHog to send events.

For more information on PostHog's session recording feature, refer to the .

For information on the identify call, refer to the guide.

RudderStack passes the user traits within the identify call to PostHog under the $set key according to the .

For information on the page call, refer to the guide.

For the page call, RudderStack sends $pageview as an event to PostHog according to the .

For information on the screen call, refer to the guide.

For the screen call, RudderStack sends $screen as an event to PostHog according to the .

For information on the track call, refer to the guide.

PostHog supports the RudderStack track call as typecapture. and sends the user action as an event to PostHog according to the .

For information on the group call, refer to the guide.

The group call sends $group as an event to PostHog according to the .

For information on the alias call, refer to the guide.

For the alias call, RudderStack sends $create_alias as an event to PostHog according to .

To pass to the PostHog JavaScript SDK, you can pass the key-value pairs as shown:

For queries on any of the sections covered in this guide, you can or start a conversation in our community.

device mode
auto-captured
PostHog documentation
RudderStack API Specification
PostHog Identify API
RudderStack API Specification
PostHog Page API
RudderStack API Specification
PostHog Screen API
RudderStack API Specification
PostHog Capture API
RudderStack API Specification
PostHog Group API
RudderStack API Specification
PostHog Alias API
super properties
contact us
Slack
FAQ
Updated group mapping
PostHog
GitHub repository
RudderStack Connection Modes
RudderStack dashboard
PostHog group mapping setting
PostHog updated group mapping settings
PostHog connection settings
PostHog web SDK settings