首先,我需要将数据从Magento导出到JSON或CSV中。然后需要将此数据导入到混合面板。Mixpanel提供了演示(见下文)。类和其他一切似乎都很好,但我很难从 Magento 获得实际数据。我尝试了很多脚本等,但无法正常工作。有什么想法吗?
<?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.
*/
$users = array(
"47859"=>"2011-01-07 12:23:01",
"47860"=>"2011-01-07 13:43:47",
"47861"=>"2011-01-07 13:54:24",
"47862"=>"2011-01-08 20:12:23",
"47863"=>"2011-01-08 22:59:29",
);
date_default_timezone_set("America/New_York"); //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 EventImporter("TOKEN_HERE","API_KEY_HERE");
foreach($users as $id=>$birthdate){
$props = array();
$props['distinct_id'] = $id; //distinct_id should be your identifier
$props['time'] = strtotime($birthdate); //time should be their $birthdate
$event = '$signup'; //you are sending the $signup event. You could also put $born here.
echo "'nSending $event event for ".$props['distinct_id']." at $birthdate (".$props['time'].")'n";
$metrics->track($event, $props);
}
class EventImporter {
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;
}
function track($event, $properties=array()) {
$params = array(
'event' => $event,
'properties' => $properties
);
if (!isset($params['properties']['token'])){
$params['properties']['token'] = $this->token;
}
$url = $this->host . 'import/?data=' . base64_encode(json_encode($params)) . "&api_key=$this->api_key";
//you still need to run as a background process
echo "$url'n";
exec("curl '" . $url . "' >/dev/null 2>&1 &");
sleep(.2);
}
}
?>
如果您的数据在CSV文件中,则可以使用分段CSV导入器轻松导入到Mixpanel。该工具建立在细分之上,如果您已经在使用细分,此过程将更加容易。有关导入数据和 csv 文件规范的信息,请访问此处。