Created
December 16, 2014 20:24
-
-
Save josue/c4dc4e1d9f7c1395f595 to your computer and use it in GitHub Desktop.
Mixpanel - Simple PHP wrapper using only the mixpanel.track() endpoint.
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 | |
// Mixpanel - Simple wrapper using only the mixpanel.track() endpoint. | |
function Mixpanel($event, $props = array(), $distinct_id = 0) { | |
$api_key = '{api-key}'; | |
$data = array( | |
'event' => $event, | |
'properties' => array( | |
'distinct_id' => $distinct_id, | |
'token' => $api_key, | |
'time' => time() | |
) | |
); | |
$data['properties'] = array_merge_recursive($data['properties'], $props); | |
$url = 'http://api.mixpanel.com/track/?data='; | |
$post = $url.base64_encode(json_encode($data)); | |
$response = file_get_contents($post); | |
return ($response == 1 ? true : false); | |
} | |
echo "Sent: " .( Mixpanel('test') ? 'Yes' : 'No'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment