diagvn/mixpanel

由Diag定制的Mix Panel供应商

1.5.4 2022-06-15 07:59 UTC

This package is auto-updated.

Last update: 2024-09-15 12:53:49 UTC


README

此库提供了一个API,用于在Mixpanel上跟踪事件和更新配置文件。

使用Composer安装

将diagvn/mixpanel添加为依赖项并运行composer update

"require": {
    ...
    "diagvn/mixpanel" : "1.*"
    ...
}

现在您可以开始跟踪事件和人员了

<?php
// import dependencies
use MixPanel\Services\MixPanelService;
// get the MixPanelService class instance, replace with your project token
$mp = new MixPanelService();
$mp->setToken("MIXPANEL_PROJECT_TOKEN");

// track an event
$mp->track("button clicked", array("label" => "sign-up"));

// create/update a profile for user id 12345
$mp->people->set(12345, array(
    '$first_name'       => "John",
    '$last_name'        => "Doe",
    '$email'            => "john.doe@example.com",
    '$phone'            => "5555555555",
    "Favorite Color"    => "red"
));

手动安装

  1. 下载Mixpanel PHP库
  2. 将zip文件解压到项目根目录下的"mixpanel-php"目录
  3. 现在您可以开始跟踪事件和人员了
<?php
// import dependencies
use MixPanel\Services\MixPanelService;
// get the MixPanelService class instance, replace with your project token
$mp = new MixPanelService();
$mp->setToken("MIXPANEL_PROJECT_TOKEN");

// track an event
$mp->track("button clicked", array("label" => "sign-up"));

// create/update a profile for user id 12345
$mp->people->set(12345, array(
    '$first_name'       => "John",
    '$last_name'        => "Doe",
    '$email'            => "john.doe@example.com",
    '$phone'            => "5555555555",
    "Favorite Color"    => "red"
));

生产提示

默认情况下,数据通过ssl和cURL发送。当您跟踪少量事件或不在乎PHP cURL调用的潜在阻塞性质时,这运行良好。然而,当您发送数百个事件(例如批量处理)时,这并不太高效。我们的库提供了一种简单的方法,可以通过持久套接字连接进行更高效的写入。要启用持久套接字,只需在实例化Mixpanel类时,在$options数组中添加条目'consumer' => 'socket'。此外,您可以通过创建自定义Consumer来贡献您自己的持久性实现。

文档

有关更多示例和选项,请查看"examples"文件夹

变更日志

版本 1.4.2

  • 初始化项目