Skip to content

Instantly share code, notes, and snippets.

@josue
Created December 16, 2014 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josue/c4dc4e1d9f7c1395f595 to your computer and use it in GitHub Desktop.
Save josue/c4dc4e1d9f7c1395f595 to your computer and use it in GitHub Desktop.
Mixpanel - Simple PHP wrapper using only the mixpanel.track() endpoint.
<?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