kingfisherdirect/magento2-posthog

PostHog Analytics integration module for Magento 2

Installs: 8

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:magento2-module

pkg:composer/kingfisherdirect/magento2-posthog

dev-main 2025-12-12 12:17 UTC

This package is auto-updated.

Last update: 2025-12-12 14:02:27 UTC


README

PostHog Analytics integration module for Magento 2.

Features

  • Global PostHog analytics integration
  • Admin panel configuration
  • CSP (Content Security Policy) whitelist included
  • Store-level configuration support
  • Easy to configure for multiple sites

Configuration

Navigate to: Stores > Configuration > General > PostHog

Settings

  • Enable PostHog: Yes/No

  • PostHog Project API Key: Your PostHog project API key (e.g., phc_...)

  • API Host: PostHog API host URL (default: https://eu.i.posthog.com)

  • Person Profiles: When to create person profiles:

    • Always
    • Identified Only (default)
    • Never

Installation

# Enable module
bin/magento module:enable KingfisherDirect_Posthog

# Run setup upgrade
bin/magento setup:upgrade

# Flush cache
bin/magento cache:flush

CLI Configuration

You can configure PostHog via CLI:

# Enable PostHog
bin/magento config:set posthog/general/enabled 1

# Set API Key
bin/magento config:set posthog/general/project_api_key "phc_YOUR_KEY_HERE"

# Set API Host
bin/magento config:set posthog/general/api_host "https://eu.i.posthog.com"

# Set Person Profiles
bin/magento config:set posthog/general/person_profiles "identified_only"

# Flush cache
bin/magento cache:flush

Multi-site Setup

For different sites, you can configure different PostHog projects:

# For a specific website
bin/magento config:set --scope=websites --scope-code=site1 posthog/general/project_api_key "phc_SITE1_KEY"
bin/magento config:set --scope=websites --scope-code=site2 posthog/general/project_api_key "phc_SITE2_KEY"

How It Works

The module adds the PostHog tracking script to all frontend pages via the default.xml layout. The script is injected into the after.body.start container for optimal performance.

File Structure

KingfisherDirect/Posthog/
├── Block/
│   └── Script.php                # Block class for rendering
├── Helper/
│   └── Data.php                  # Helper for configuration
├── Model/
│   └── Config/
│       └── Source/
│           └── PersonProfiles.php # Source model for dropdown
├── etc/
│   ├── acl.xml                   # ACL configuration
│   ├── adminhtml/
│   │   └── system.xml            # Admin system configuration
│   ├── config.xml                # Default configuration values
│   ├── csp_whitelist.xml         # CSP whitelist
│   └── module.xml                # Module declaration
├── view/
│   └── frontend/
│       ├── layout/
│       │   └── default.xml       # Global layout
│       └── templates/
│           └── script.phtml      # PostHog script template
└── registration.php              # Module registration