wp-media/wp-mixpanel
Composer 安装命令:
composer require wp-media/wp-mixpanel
包简介
WordPress Mixpanel Integration
README 文档
README
A library for integrating Mixpanel analytics into WordPress projects of Group.One.
Overview
WP Mixpanel provides seamless integration between WordPress and Mixpanel, allowing you to track events in your WordPress projects.
Installation
Via Composer
Add the package to your project using Composer:
composer require wp-media/wp-mixpanel
Configuration
The library is composed of 3 main classes:
Optinhandles the status of the opt-in for analyticsTrackingis the base class for interaction with MixpanelTrackingPluginextends theTrackingclass with some specific configuration for usage in WordPress plugins
Initialize the Tracking class alone
new WPMedia\Mixpanel\Tracking( $mixpanel_token, $options = [] );
The $mixpanel_token is the token provided by Mixpanel corresponding to the project you want to send data to.
For Group.One, we have a sandbox project and a production project.
The $options parameter is an optional array which can be used to configure further the Mixpanel PHP library configuration.
Initialize the TrackingPlugin in a WordPress plugin
new WPMedia\Mixpanel\TrackingPlugin( $mixpanel_token, $plugin, $brand = '', $app = '' );
- The
$pluginis the plugin name + the version - The
$brandand$appare optional, but should be specified based on the analytics requirements of the plugin you implement the library in.
Initialize the Optin class
new WPMedia\Mixpanel\Optin( $plugin_slug, $capability );
- The
$plugin_slugis the slug used in your plugin as the prefix for options - The
$capabilityis the capability required to be able to modify the value of the optin
Usage Examples
Track a simple event without optin
$tracking->identify( $user_id ); $tracking->track( 'Event Name', $properties );
Calling identify() is required to associate sent events with a user ID. The $user_id provided is automatically hashed with the appropriate algorithm.
The track() method takes 2 required arguments:
- The
$event_namecorresponding to the event name which should be displayed in Mixpanel. Events use Start Case formatting. - The
$propertiesis an array of properties to associate with the event in the formatproperty_name => value. Properties use small caps formatting and underscores.
Track an event with optin check in a plugin
if ( ! $optin->can_track() ) { return; } $tracking_plugin->identify( $user_id ); $tracking_plugin->track( 'Event Name', $properties, $event_capability = '' );
The track() method of the TrackingPlugin class is a bit different than its parent:
First, it takes an additional optional parameter $event_capability. By default, the capability required for all events is manage_options. This can be changed in two different ways:
- Using the filter
wp_mixpanel_event_capabilityto modify the value for all events - Passing the capability as the parameter
$event_capability, to set it on a specific event
Second, the method will automatically associate the following properties to the event:
domain: hashed value of the current hostnamewp_version: current WP versionphp_version: current PHP versionplugin: Plugin name and version (set in constructor)brand: Brand name (set in constructor)application: Application name (set in constructor)
wp_mixpanel_event_capability Filter usage
The filter can takes 3 arguments:
$capabilitythe capability for all events$eventthe current event name$appthe current app name
Read more about MixPanel at group.one
More information about how MixPanel is used at group.one is available in our internal documentation.
wp-media/wp-mixpanel 适用场景与选型建议
wp-media/wp-mixpanel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 289.53k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wp-media/wp-mixpanel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wp-media/wp-mixpanel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 289.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2025-05-22