I’ve observed time and again that many Shopify store owners are searching for comprehensive analytics solutions and perhaps an A/B testing tool to gain deeper insights into their stores. While Shopify’s analytics section helps in understanding trends and overall website health, there’s still a need for a more in-depth tool that can explain why a shop isn’t converting. That’s where PostHog on Shopify comes in. In this blog, I’ll show you how we addressed that need using PostHog, at least to start gathering data for now. Although we are aware of PostHog’s Shopify installation documentation, we found it lacking or not suitable for a full-coverage installation. So we wrote our own guide.

Before jumping into the step-by-step PostHog installation guide, make sure you have met these requirements:

Step 1: Grab the PostHog snippet

Similar to step 1 in Installing PostHog on WordPress, start by grabbing your PostHog snippet from your project’s settings:

  1. Log in to your PostHog account.
  2. Navigate to Project Settings.
  3. Find the Web snippet section and copy the HTML snippet provided.

Note: If you see person_properties set to 'identified_only' in the script, change it to 'always' for maximum coverage. This ensures that all user interactions are tracked, even for anonymous users.

Decorative

Did you know?

We can just do things for you!

Contact Us

Step 2: Inject the Snippet into Your Shopify Theme

In Shopify, go to Sales Channels → Online Store → Themes.
Click on the three dots next to your theme’s name and select Edit code.

PostHog on Shopify step1
Shopify theme

You will see your theme files there. It will look like this:

PostHog on Shopify step1-02
Adding the PostHog snippet to Shopify theme

In the left sidebar, find and click on theme.liquid.
Paste your copied PostHog snippet just after the opening <head> tag.
Click Save and exit.
This will ensure that the PostHog tracking script is loaded on every page of your store.

Step 3: Capture Shopify events in PostHog

Capturing native Shopify events like checkout_complete or checkout_started is crucial for reliable conversion rate optimization analysis. To do this, we’ll use Customer Events.

  1. In your Shopify admin dashboard, click on Settings (icon in the bottom left corner).
  2. Select Customer events from the left sidebar.
  3. Click the Add custom pixel button.
  4. In the dialog box that opens enter a name for your pixel (e.g., PostHog).
PostHog on Shopify step3-01

Configure your pixel’s customer privacy settings according to your store’s privacy policy and compliance requirements.
Paste the following snippet into the code section.

Then to save, click the connect button.

The reason we use this custom snippet is to capture all standard events, helping us gain a clearer understanding of user behavior on our website. You can view the exact events captured by this snippet through this link.

PostHog on Shopify step3-02
Connect PostHog with Shopify

Step 4: Verify Installation

You should now be able to see events like Pageviewcheckout_startedproduct_added_to_cart, and checkout_completed coming into PostHog:

  1. Go back to your PostHog dashboard.
  2. Navigate to Activity or Events to verify that data is being collected.
  3. Perform some actions on your Shopify store (e.g., add a product to the cart) to test if events are recorded.
PostHog on Shopify step4
Viewing Shopify events in PostHog

Conclusion

By following these steps, you can integrate PostHog with your Shopify store to gain deeper insights into customer behavior and improve your conversion rates. Happy analyzing!

Need further assistance? Feel free to leave a comment below or reach out to us for more help.

Frequently asked qusetions

The PostHog web snippet in theme.liquid ensures PostHog runs on every storefront page and can autocapture clicks, page views, and other client-side interactions. The Shopify custom pixel subscribes to Shopify’s standard customer events (like checkout_started and checkout_completed) from the Web Pixels API, including checkout and post-purchase pages that the theme snippet alone may not fully cover. Using both gives you full funnel coverage. (+)

Yes. As long as your theme has a theme.liquid (or equivalent layout file where you can inject code into <head>), the PostHog snippet will load across all pages. The custom pixel part is theme-independent because it’s managed from Settings → Customer events, so it still fires on checkout and post-purchase, even if you later change themes. (+)

With a properly written custom pixel, you can subscribe to Shopify’s standard events like page_viewed, product_viewed, cart_viewed, product_added_to_cart, product_removed_from_cart, checkout_started, checkout_contact_info_submitted, checkout_shipping_info_submitted, payment_info_submitted, and checkout_completed.
Your pixel then forwards those events to PostHog via posthog.capture, so you see all key funnel steps inside PostHog.

Yes. The Shopify Web Pixels API lets you subscribe to custom events and enrich standard ones inside your custom pixel. (+)
In that code, you can call posthog.capture('my_custom_event', { …properties }) to send any event you care about—upsell clicks, subscription activations, post-purchase surveys, etc. into PostHog.

PostHog’s web snippet is designed to load asynchronously and not block page rendering.
The custom pixel also runs in Shopify’s pixel sandbox, which is optimized for marketing/analytics scripts.
As with any script, there is some overhead, but for a normal store it’s negligible if implemented correctly.

After installation:

  1. Open your store in a fresh browser session and perform key actions (view product, add to cart, start checkout, complete test order).

  2. In PostHog, go to Events / Activity and filter by your recent events to confirm page_viewed, product_added_to_cart, checkout_started, checkout_completed, etc. are arriving with sensible properties.

  3. If something’s missing, add console.log() inside your custom pixel or use browser dev tools to ensure the pixel runs on the right pages and sends the posthog.capture calls.

Yes. Once PostHog is installed, you can use Experiments and feature flags to run A/B tests.
On Shopify, you usually:

  • Use a feature flag to assign visitors to variant A or B.

  • Switch layouts, sections, or content in your theme based on that flag.

Conversions (like checkout_completed or product_added_to_cart) are already tracked by your custom pixel, so PostHog can calculate which variant wins.

Partially. For a headless / Hydrogen storefront:

  • You’d install the PostHog web SDK in your frontend framework instead of theme.liquid.

  • You can still use Shopify customer events + custom pixel to capture checkout events and send them to PostHog.

So the idea is the same, but the “theme snippet” piece becomes a frontend integration instead of a Liquid edit.

PostHog markets itself as privacy-friendly web analytics; it supports cookie-less tracking and gives you control over what you capture and store.
Shopify’s customer events and custom pixels also come with customer privacy settings, so you can respect consent preferences when your pixel runs.
You’re still responsible for implementing a compliant consent banner and configuring PostHog and your pixel to honor “do not track” choices; this setup just gives you the tools to do it.

There are third-party Shopify apps (for example, PixieHog) that wrap the PostHog–Shopify integration in a no-code UI and automatically subscribe to Shopify web pixel events.
For simple stores, that’s convenient. The manual method in this article gives you more control and visibility over exactly which events are captured and how they’re sent into PostHog.

PostHog offers a free tier with a generous event limit (commonly around 1M events per month) plus some session recordings, which is usually enough for smaller and mid-sized stores to get started.
If you have high traffic, lots of recordings, or heavy experimentation, you may eventually need a paid plan—but you can implement and validate this setup before committing.

Yes. PostHog lets you:

  • Use one project and add a property like store_id or domain to distinguish events from different stores, or

  • Create separate projects per store inside the same organization if you want isolated dashboards and permissions.

Your custom pixel code can add those identifiers as properties on every posthog.capture call.

They won’t match 1:1. GA4 and Shopify reports use their own definitions, sampling rules, and attribution windows. PostHog is event-based, unsampled, and focused on product and funnel analytics.
Use Shopify for financial/accounting numbers and GA4 for broad marketing reporting, but rely on PostHog for behavior analysis, funnel diagnostics, and A/B test results.

If you’re seeing page views but no checkout events:

  1. Confirm your custom pixel is added under Settings → Customer events and is enabled.

  2. Check your pixel code is actually subscribing to events like checkout_started and checkout_completed from Shopify’s Web Pixels API.

  3. Review privacy settings—if customer consent is required and not granted, the pixel may never fire.

  4. Use console.log and browser dev tools to verify the pixel runs on checkout pages and that posthog.capture calls are being executed.

Related blog posts

Leave a Reply

Your email address will not be published. Required fields are marked *