/** * @param string $event * @param array $properties * * @internal param array $data */ public function track($event, $properties = []) { $browserInfo = new Browser(); $osInfo = new Os(); $deviceInfo = new Device(); $browserVersion = trim(str_replace('unknown', '', $browserInfo->getName() . ' ' . $browserInfo->getVersion())); $osVersion = trim(str_replace('unknown', '', $osInfo->getName() . ' ' . $osInfo->getVersion())); $hardwareVersion = trim(str_replace('unknown', '', $deviceInfo->getName())); $data = ['Url' => $this->request->getUri(), 'Operating System' => $osVersion, 'Hardware' => $hardwareVersion, '$browser' => $browserVersion, 'Referrer' => $this->request->header('referer'), '$referring_domain' => $this->request->header('referer') ? parse_url($this->request->header('referer'))['host'] : null, 'ip' => $this->request->ip()]; $data = array_filter($data); $properties = array_filter($properties); if (!array_key_exists('$browser', $data) && $browserInfo->isRobot()) { $data['$browser'] = 'Robot'; } parent::track($event, $data + $properties); }
// 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); // append a new favorite to John's favorites $mp->people->append($user_id, "favorites", "Apples"); // append a few more favorites to John's favorites $mp->people->append($user_id, "favorites", array("Baseball", "Reading")); // track a purchase or charge of $9.99 for user 12345 where the transaction happened just now $mp->people->trackCharge($user_id, "9.99");
<?php require_once "../lib/Mixpanel.php"; // import the Mixpanel class require_once "consumers/ObConsumer.php"; // import the Mixpanel class // define a callback function to handle errors made in a consumer function handleError($code, $data) { echo "This is my customer error handler. I've received an error! code = " . $code . " : data = " . $data . "<br />"; } // instantiate Mixpanel with some different options including a custom consumer and a custom error callback $mp = new Mixpanel("MIXPANEL_PROJECT_TOKEN", array("debug" => true, "max_batch_size" => 1, "consumers" => array("ob" => "ObConsumer"), "consumer" => "ob", "error_callback" => "handleError")); $mp->track("test_event", array("color" => "blue")); $mp->track("test_event", array("color" => "red")); $mp->track("force_error"); // a magical event we've defined as an error in our custom "ObConsumer"
function processLenderInvite($invitee, $lender_invite_visit) { global $database; $lender_invite = array(); if ($lender_invite_visit['lender_invite_id']) { $lender_invite = $database->getLenderInviteById($lender_invite_visit['lender_invite_id']); if (!$lender_invite) { return false; } } for ($retry = 0; $retry < 3; $retry++) { $database->startDbTxn(); $amount = 25; if ($lender_invite) { $res1 = $database->updateLenderInvite($lender_invite['id'], $invitee['userid']); } else { $lender_invite = $database->addLenderInvite(array('lender_id' => $lender_invite_visit['lender_id'], 'email' => $invitee['Email'], 'invitee_id' => $invitee['userid'], 'hash' => null)); $res1 = $lender_invite !== false; } $res2 = $database->setLenderInviteTransaction($lender_invite['lender_id'], $amount, 'Lender invite credit', LENDER_INVITE_INVITER); $res3 = $database->setLenderInviteTransaction($invitee['userid'], $amount, 'Lender invitee credit', LENDER_INVITE_INVITEE); if ($res1 && $res2 && $res3) { $database->commitTxn(); $lender = $database->getLenderDetails($lender_invite['lender_id']); if ($lender['invite_notify']) { $this->sendLenderInviteCredit($lender_invite); } Mixpanel::track('Invite accepted', array('username' => $invitee['username'], 'email' => $lender_invite['email'], 'lender_id' => $lender_invite['lender_id'])); $mixpanel = MixpanelClient::getInstance(MIXPANEL_TOKEN); $mixpanel->identify($lender_invite['lender_id']); $share_type = $lender_invite_visit['share_type']; $share_types = array(1 => 'email', 2 => 'twitter', 3 => 'facebook'); $mixpanel->track('Recruited new lender', array('share_type' => array_get($share_types, $share_type, 'website'), 'lender_id' => $lender_invite['lender_id'], 'invitee_id' => $lender_invite['invitee_id'])); $mixpanel->people->set($lender_invite['lender_id'], array('Recruited new lender' => date('Y-m-d H:i:s')), '0'); $mixpanel->people->increment($lender_invite['lender_id'], 'Recruited new lender counter', 1, '0'); return $lender_invite; } else { $database->rollbackTxn(); } } return false; }
$lender = $database->getLenderDetailsByUsername(sanitize($_GET['username'])); if (!$lender) { header("Location: " . SITE_URL); } $yc_account_credit = $session->amountToUseForBid(YC_ACCOUNT_ID); if ($yc_account_credit < 5000) { return $smarty->display('lender_invite_inactive.tpl'); } if (!$session->userid) { if (isset($_GET['h'])) { $share_type = 1; $lender_invite = $database->getLenderInviteByHash($_GET['h'], $lender['userid']); if ($lender_invite) { if (!$lender_invite_visit || $lender_invite_visit['lender_invite_id'] != $lender_invite['id']) { $lender_invite_visit = array('lender_id' => $lender['userid'], 'lender_invite_id' => $lender_invite['id'], 'share_type' => $share_type); $_SESSION['lender_invite_visit'] = $database->addLenderInviteVisit($lender_invite_visit); header("Location: /i/" . $lender['username']); } } Mixpanel::track('Invite page viewed', array('share_type' => array_get($share_types, $share_type, 'website'), 'email' => $lender_invite['email'], 'lender_id' => $lender['userid'])); } elseif (!$lender_invite_visit || $lender_invite_visit['lender_id'] != $lender['userid']) { $lender_invite_visit = array('lender_id' => $lender['userid'], 'lender_invite_id' => null, 'share_type' => $share_type); $_SESSION['lender_invite_visit'] = $database->addLenderInviteVisit($lender_invite_visit); Mixpanel::track('Invite page viewed', array('share_type' => array_get($share_types, $share_type, 'website'), 'lender_id' => $lender['userid'])); } } $lender_name = $lender['FirstName'] ?: $lender['username']; $lender_url = SITE_URL . getUserProfileUrl($lender['userid']); $lender_profile_image = $database->getProfileImage($lender['userid']); $smarty->assign(compact('lender_name', 'lender_url', 'lender_profile_image')); $smarty->display('lender_invitee.tpl');
$version = $versions[array_rand($versions)]; if (!$session->userid) { if (isset($_GET['h'])) { $share_type = 1; $lender_invite = $database->getLenderInviteByHash($_GET['h'], $lender['userid']); if ($lender_invite) { if (!$lender_invite_visit || $lender_invite_visit['lender_invite_id'] != $lender_invite['id']) { $lender_invite_visit = array('lender_id' => $lender['userid'], 'lender_invite_id' => $lender_invite['id'], 'share_type' => $share_type, 'invitee_landing_version' => $version); $_SESSION['lender_invite_visit'] = $database->addLenderInviteVisit($lender_invite_visit); header("Location: /i/" . $lender['username']); } } Mixpanel::track('Invite page viewed', array('share_type' => array_get($share_types, $share_type, 'website'), 'email' => $lender_invite['email'], 'lender_id' => $lender['userid'], 'invitee_landing_version' => $version)); } elseif (!$lender_invite_visit || $lender_invite_visit['lender_id'] != $lender['userid']) { $lender_invite_visit = array('lender_id' => $lender['userid'], 'lender_invite_id' => null, 'share_type' => $share_type, 'invitee_landing_version' => $version); $_SESSION['lender_invite_visit'] = $database->addLenderInviteVisit($lender_invite_visit); Mixpanel::track('Invite page viewed', array('share_type' => array_get($share_types, $share_type, 'website'), 'lender_id' => $lender['userid'], 'invitee_landing_version' => $version)); } } $lender_name = $lender['username']; if ($lender['userid'] == 19602) { $lender_name = "God"; } $lender_url = SITE_URL . getUserProfileUrl($lender['userid']); $lender_profile_image = $database->getProfileImage($lender['userid']); $smarty->assign(compact('lender_name', 'lender_url', 'lender_profile_image')); if ($version == 'try_microlending_header') { $smarty->display('lender_invitee_new.tpl'); } else { $smarty->display('lender_invitee.tpl'); }
function processLenderInvite($invitee, $lender_invite_visit) { global $database; $lender_invite = array(); if ($lender_invite_visit['lender_invite_id']) { $lender_invite = $database->getLenderInviteById($lender_invite_visit['lender_invite_id']); if (!$lender_invite) { return false; } } for ($retry = 0; $retry < 3; $retry++) { $database->startDbTxn(); $amount = 25; if ($lender_invite) { $res1 = $database->updateLenderInvite($lender_invite['id'], $invitee['userid']); } else { $lender_invite = $database->addLenderInvite(array('lender_id' => $lender_invite_visit['lender_id'], 'email' => $invitee['Email'], 'invitee_id' => $invitee['userid'], 'hash' => null)); $res1 = $lender_invite !== false; } $res2 = $database->setLenderInviteTransaction($lender_invite['lender_id'], $amount, 'Lender invite credit', LENDER_INVITE_INVITER); $res3 = $database->setLenderInviteTransaction($invitee['userid'], $amount, 'Lender invitee credit', LENDER_INVITE_INVITEE); if ($res1 && $res2 && $res3) { $database->commitTxn(); $this->sendLenderInviteCredit($lender_invite); Mixpanel::track('Invite accepted', array('username' => $invitee['username'], 'email' => $lender_invite['email'], 'lender_id' => $lender_invite['lender_id'])); return $lender_invite; } else { $database->rollbackTxn(); } } return false; }