Mixpanel — получить пользователей (distinct_id или другое свойство) на основе отслеживаемых событий

Я пытался найти правильный API, чтобы получить «список пользователей», которые сделали «Событие».

Например, в Mixpanel отслеживается событие под названием «Создан профиль», и я хочу получить список пользователей, которые выполнили это событие между диапазоном дат,

Я использую этот API, предоставленный ими https://mixpanel.com/docs/api-documentation/data-export-api#libs-php

Я обнаружил, что «живой» API работает близко к моему требованию, но не поддерживает диапазон дат. Образец «живого» запроса API,

$api_key = 'XXX';
$api_secret = 'XXX';
$this->load->library('mixpanel_export');
$this->mixpanel_export->init($api_key, $api_secret);

$data = $this->mixpanel_export->request(array('live'), array(
                    'event' => 'Received Rating',
                    'on' => '5 in properties["level"]',
                    'start_time' => 0
                ));

Может ли кто-нибудь помочь мне? Спасибо!


person rAjA    schedule 04.07.2014    source источник


Ответы (1)


Проверьте, поможет ли вам скрипт здесь

https://gist.github.com/dawalama/34155428ff8f53e4d508

<?php

// Based on https://mixpanel.com/docs/api-documentation/exporting-raw-data-you-inserted-into-mixpanel
class MixpanelExport {

    private $api_url = 'https://data.mixpanel.com/api/2.0/export';
    private $api_key;
    private $api_secret;
    public $debug;

    public function __construct($api_key, $api_secret) {
        $this->api_key = $api_key;
        $this->api_secret = $api_secret;
        $this->debug = false;
    }

    public function export($params) {

        if (empty($params)) {
            return false;
        }

        if (!isset($params['api_key'])) {
            $params['api_key'] = $this->api_key;
        }

        if (!isset($params['expire'])) {
            $current_utc_time = time() - date('Z');
            $params['expire'] = $current_utc_time + 100000; // Default 10 minutes
        }

        $sig = $this->signature($params);
        $request_url = $this->api_url . '?sig=' . $sig . '&'. http_build_query($params);

        if ($this->debug) {
            echo "\nURI: $request_url\n";
        }

        $curl_handle = curl_init();
        curl_setopt($curl_handle, CURLOPT_URL, $request_url);
        curl_setopt($curl_handle, CURLOPT_HEADER, 0);
        curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($curl_handle);
        curl_close($curl_handle);
        return $data;
    }

    private function signature($params) {
        /**
         * Algorithm to generate signature
         *
         * args = all query parameters going to be sent out with the request 
         * (e.g. api_key, unit, interval, expire, format, etc.) excluding sig.
         *
         * args_sorted = sort_args_alphabetically_by_key(args)
         *
         * args_concat = join(args_sorted) 
         *
         * # Output: api_key=ed0b8ff6cc3fbb37a521b40019915f18&event=["pages"]
         * #         expire=1248499222&format=json&interval=24&unit=hour
         *
         * sig = md5(args_concat + api_secret)
         **/
        ksort($params);
        $param_string = '';
        foreach ($params as $key=>$value) {
            $param_string .= $key . '=' . $value;
        }
        return md5($param_string . $this->api_secret);
    }
}

/** Example usage
 *
 * $api_key = "<your api key>";
 * $api_secret = "<your secret key>";
 * $params = [
 * 'from_date'=>'2014-01-01',
 * 'to_date'=>'2014-02-01',
 * 'event'=>["event-x"]
 * ];
 *
 * $exporter = new MixpanelExport($api_key, $api_secret);
 * echo $exporter->export($params);
 ** 

Вы должны использовать конечную точку, описанную здесь https://mixpanel.com/docs/api-documentation/exporting-raw-data-you-inserted-into-mixpanel

person dminer    schedule 25.11.2014