Last active
December 28, 2015 08:49
-
-
Save juliend2/7473965 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Example script that will import $born events into your Mixpanel projects for your existing users. | |
Feel free to modify. If you have a high number of users you might want to use some sort of queing system instead of | |
a sleep command to make sure that all the requests get sent propertly. | |
*/ | |
/* | |
Dummy Data: | |
This array represents the data you would fetch from your own database that would have user_ids and the date you would like to set as their | |
birthdate. Mixpanel will use this birthdate to determine their cohort. | |
*/ | |
$project_token = "[something]"; // Portal | |
$api_key = "[something]"; // portal | |
$users = array( | |
'13c595d0-9bf5-0130-b1a0-7a163e02a1d3' => '2013-04-26 23:12:59', | |
); | |
date_default_timezone_set("UTC"); //set for the timezone your sign up data is using. | |
//Constructer: new EventImporter("Project Token","Project API Key"); | |
//Both these values are on your mixpanel accounts page: http://mixpanel.com/account/ | |
$metrics = new UserProfileImporter($project_token, $api_key); | |
foreach($users as $id=>$birthdate){ | |
$user = array(); | |
$user['distinct_id'] = $id; //distinct_id should be your identifier | |
$user['set'] = array('$name'=>'Anne-Lyse', '$email'=>'[email protected]', '$created'=>'2013-04-26 23:12:59'); | |
echo "\nSending $user user.\n"; | |
$metrics->import($user); | |
} | |
class UserProfileImporter { | |
public $token; | |
public $api_key; | |
public $host = "http://api.mixpanel.com/"; | |
public function __construct($token_string, $api_key) { | |
$this->token = $token_string; | |
$this->api_key = $api_key; | |
} | |
public function import($user = array()) { | |
$user['token'] = $this->token; | |
// print_r($user); die; | |
$url = $this->host . 'engage/?data=' . base64_encode(json_encode($user)) . "&api_key=$this->api_key"; | |
echo "$url\n"; | |
exec("curl '" . $url . "' >/dev/null 2>&1 &"); | |
sleep(.2); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment