Add PostHog to Joomla

Your pageview counter says 400 people visited your pricing page yesterday, and that's the whole story it can tell. You still have no idea where visitors gave up in your signup flow, which button nobody clicks, or what a frustrated visitor did right before leaving. PostHog answers those questions with funnels, session recordings, and heatmaps, without shipping your visitors' data to an ad network.

Setting up PostHog in Joomla comes down to loading one script, and you don't need a dedicated plugin for it. You can add PostHog to your Joomla site using Code Snippets.

What is PostHog

PostHog is an open-source product analytics platform. It combines event tracking, funnels, session recordings, heatmaps, and feature flags in one tool, and can run on PostHog Cloud or on your own server.

How to get the PostHog project API key

You need a PostHog account, either on PostHog Cloud or a self-hosted instance.

  1. Go to PostHog and sign in, or create an account and a project.
  2. Open Settings → Project → Project API key.
  3. Copy the key. It starts with phc_.
  4. Note your instance host as well: https://eu.i.posthog.com for PostHog Cloud EU, https://us.i.posthog.com for PostHog Cloud US, or your own domain if you self-host.

How to Add PostHog to Joomla

  1. Install Code Snippets if it is not installed already.
  2. Go to Joomla Administrator.
  3. Open Components -> Code Snippets.
  4. Click New.
  5. Give your snippet a descriptive title like "PostHog Analytics".
  6. Select HTML snippet type.
  7. Paste the following code, replacing phc_YOUR_PROJECT_API_KEY with your key and api_host with your own instance:
    <script>
    !function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys".split(" "),n=0;n
    
  8. Select Site Header as the Insertion Method.
  9. Publish the snippet.
  10. Optionally, open the Conditional Logic tab to restrict which pages the snippet runs on. A common choice is to exclude logged-in administrators so your own visits stay out of the data. Leave it empty to run it site-wide. Learn more in Using Conditional Logic.

Congrats! You've successfully added PostHog to your Joomla site without installing another plugin.

Track a Custom Event

PostHog captures page views automatically. To record a specific action, add a second snippet with JS as the snippet type, set the Insertion Method to Site Footer, and use Conditional Logic to limit it to the right page:

posthog.capture('signup_completed', {
    plan: 'pro'
});

Verify it Works

Visit your site once, then open your PostHog project and go to Activity. Your page view appears within seconds, with the event stream showing the URL you visited. If nothing arrives, confirm the snippet is published, that the API key is correct, and that api_host points at the right region. A key from the EU cloud sending to the US host silently records nothing.

For more information about snippet types and insertion methods, visit our documentation: https://www.tassos.gr/docs/tassos-code-snippets/

Last updated on Aug 14th 2026 15:08