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

  1. Enable the Integration:

    Navigate to Business Settings > Checkout > Advanced Settings, then toggle Enable PostHog Analytics for Hosted Checkout.:

  2. 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

  3. 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.

  4. 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

http://example.com/pay/ea25713d-313f-41f3-bf05-72bf00231d5e

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

op_open_checkout_page

Fired when the hosted checkout page is first loaded

(This event has no properties.)

op_select_payment_method

Fired when the customer selects a payment method

Properties:

  • provider - the payment provider

  • processor_name - the name of the specific processor, if applicable. Note that this will not be filled up for credit cards

op_checkout_started

Fired when checkout first starts (i.e. when the customer hits submit)

(This event has no properties.)

op_setup_payment_method_success

Fires when the customer succeeds with payment method setup (only available on setup mode)

Properties:

  • payment_method_id - the ID of the payment method created as a result of setup

op_checkout_success

Fires when the customer succeeds with checkout (only available on checkout mode)

Properties:

  • invoice_urls - the list of invoice URLs resulting from the checkout

op_checkout_error

Fires when the customer encounters an error during checkout (or setup)

Properties:

  • error - the full error message

  • error_code - the standardized error code (e.g. FRAUD_RISK_TOO_HIGH)

Other PostHog events (typing, mouse clicks) are also enabled by default.