Kirby wrapper for Posthog

Installs: 289

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 0


3.5.1 2024-07-15 14:05 UTC

This package is auto-updated.

Last update: 2024-07-15 14:05:39 UTC


Release Downloads Twitter

Kirby 3/4 Plugin for connecting Kirby to Posthog


Using composer:

composer require bnomei/kirby3-posthog

Using git submodules:

git submodule add site/plugins/kirby3-posthog

Using download & copy: download the latest release and copy to site/plugins

Commerical Usage

Support open source!

This plugin is free but if you use it in a commercial project please consider to sponsor me or make a donation.
If my work helped you to make some cash it seems fair to me that I might get a little reward as well, right?

Be kind. Share a little. Thanks.

‐ Bruno


You can set the apikey and host in the config.


return [
    // other config settings ...
    'bnomei.posthog.apikey' => 'YOUR-KEY-HERE',
    '' => 'YOUR-HOST-HERE',

You can also set a callback if you use the dotenv Plugin.


return [
    // other config settings ...
    'bnomei.posthog.apikey' => function() { return env('POSTHOG_APIKEY'); },
    '' => function() { return env('POSTHOG_HOST'); },


Output the tracking Javascript via the snippet included in the plugin.

  <?php snippet('posthog'); ?>


PHP track pageview


// track page view event for current kirby user or identified posthog user

// be careful to not have any whitespace before <html>
    <!-- ... --->

PHP helper function

Use the posthog()-helper to access Posthog. You can use all methods from the Posthog PHP library.


    'distinctId' => site()->posthogDistinctId(),
    'event' => 'movie played',
    'properties' => array(
        'movieId' => '123',
        'category' => 'romcom'

NOTE: Using the static class from the official posthog docs is not supported.

In addition to the posthog()-helper this plugin adds the following features to the original library.

  • Disabled on localhost by default
  • Cache for Feature Flag list - it would otherwise send a http request to your posthog instance every time you access the list. It still will send one for every feature flag check.


Read more about apikey and personalapikey here:



This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.



It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.