PostHog Shopify

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.

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 Step2-01

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

PostHog on Shopify step2-02

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.

PostHog on Shopify step3-02

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-01

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.

Similar Posts

Leave a Reply

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