bnomei/kirby3-posthog 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bnomei/kirby3-posthog

最新稳定版本:5.3.0

Composer 安装命令:

composer require bnomei/kirby3-posthog

包简介

Kirby Plugin for interfacing with Posthog

README 文档

README

Release Discord Buymecoffee

Kirby Plugin for interfacing with Posthog

Install

  • unzip master.zip as folder site/plugins/kirby3-posthog or
  • git submodule add https://github.com/bnomei/kirby3-posthog.git site/plugins/kirby3-posthog or
  • composer require bnomei/kirby3-posthog

Setup

You can set the apikey and host in the config.

site/config/config.php

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

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

site/config/config.php

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

Javascript

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

  <?php snippet('posthog'); ?>
  </body>
</html>

Usage

PHP track pageview

site/template/default.php

<?php
// track page view event for current kirby user or identified posthog user
$page->posthogCapturePageView();

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

PHP helper function

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

<?php

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

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.

Warning

Using the static class from the official Posthog docs is not supported.

Settings

bnomei.posthog. Default Description
apikey string or callback
personalapikey string or callback
host string or callback
enabled true or false or 'force' but disabled on localhost setups by default
featureflags 1 duration (in minutes) to cache the feature flags in minutes

Tip

Read more about apikey and personalapikey here: https://posthog.com/docs/api

Dependencies

Disclaimer

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.

License

MIT

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.

统计信息

  • 总下载量: 467
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固