Пример #1
0
require_once "/path/to/vendor/mixpanel/mixpanel-php/lib/Mixpanel.php";
// import the Mixpanel class
$mp = new Mixpanel("MIXPANEL_PROJECT_TOKEN", array("debug" => true));
// this would likely come from a database or session variable
$user_id = 12345;
// associate user 12345 to all subsequent track calls
$mp->identify($user_id);
// send property "color" = "red" with all subsequent track calls
$mp->register("color", "red");
// send property "number" = 1 with all subsequent track calls, don't overwrite an existing value
$mp->registerOnce("number", 1);
$mp->registerOnce("number", 2);
// this will do nothing
// send all of these properties with all subsequent track calls, overwriting previously set values
$mp->registerAll(array("color" => "green", "prop2" => "val2"));
// color is now green instead of red
// send all of these properties with all subsequent track calls, NOT overwriting previously set values
$mp->registerAllOnce(array("color" => "blue", "prop3" => "val3"));
// color is still green but prop3 is now set to val3
// track a custom "button click" event
$mp->track("button click", array("label" => "Login"));
// track a custom "logged in" event
$mp->track("logged in", array("landing page" => "/specials"));
// create/update a profile identified by id 12345 with $first_name set to John and $email set to john.doe@example.com
// now we can send them Notifications!
$mp->people->set($user_id, array('$first_name' => "John", '$email' => "*****@*****.**"));
// update John's profile with property ad_source to be "google" but don't override ad_source if it exists already
$mp->people->setOnce($user_id, array("ad_source" => "google"));
// increment John's total logins by one
$mp->people->increment($user_id, "login count", 1);