PostHog for Hosted Checkout
How to integrate your PostHog account with your Hosted Checkout page
About this Integration
OpenPay offers a native integration with PostHog, specifically designed for Hosted Checkout.
Note: This integration is not required for Embedded Checkout, as PostHog can be directly integrated into your own webpage.
This integration enables you to publish events from your Hosted Checkout page to your PostHog instance. It is particularly useful if you want to maintain a unified user journey across the onboarding and checkout flow.
Configuration Steps
-
Enable the Integration:
Navigate to Business Settings > Checkout > Advanced Settings, then toggle Enable PostHog Analytics for Hosted Checkout.:
-
Add Your API Key:
After enabling, enter your PostHog Project API Key (typically prefixed with
phc_
). You can find this key in your PostHog project's settings:The project API key in the PostHog Project Settings page Add this key to your PostHog Configuration in OpenPay -
Customize Initialization: You may pass a custom configuration object to
posthog.init
, using the PostHog Init Keys field (see screenshot above). This object will be used as the second argument in the function call — please refer to the PostHog configuration documentation for supported options.Important: If setting a custom
api_host
, please ensure that it supports CORS for your hosted checkout domain. -
Web Analytics Domains (Optional): To enable PostHog's web analytics for the checkout page, add your checkout domain to:
PostHog Project Settings > Web Analytics Domains:
Assigning a Custom User ID
By default, the PostHog user ID is assigned in the format:op-checkout-<checkout-session-token>
To associate this with your own user ID, append the phid
parameter as a URL hash to the checkout URL:
Example:
Original URL |
|
With custom user ID |
http://example.com/pay/ea25713d-313f-41f3-bf05-72bf00231d5e#phid=custom_uid_123 |
This method works for both Checkout Session URLs and Payment Link URLs.
Internally, OpenPay uses PostHog aliasing to merge the custom user ID with the checkout-session-based ID. This allows you to do un-splitting later if needed.
PostHog Events Reference
The hosted checkout page publishes the following PostHog events:
Event Name |
Description |
---|---|
|
Fired when the hosted checkout page is first loaded (This event has no properties.) |
|
Fired when the customer selects a payment method Properties:
|
|
Fired when checkout first starts (i.e. when the customer hits submit) (This event has no properties.) |
|
Fires when the customer succeeds with payment method setup (only available on Properties:
|
|
Fires when the customer succeeds with checkout (only available on Properties:
|
|
Fires when the customer encounters an error during checkout (or setup) Properties:
|
Other PostHog events (typing, mouse clicks) are also enabled by default.