Skip to content

Instantly share code, notes, and snippets.

@agramonte

agramonte/analytics.php

Last active Mar 14, 2021
Embed
What would you like to do?
<?php
if( $_GET["api_key"] && ($_GET["user_id"] || $_GET["device_id"] ) && $_GET["event_type"] ) {
// Required data
$data = array(
'event_type' => $_GET['event_type']
);
if( $_GET["user_id"] ) {
$data['user_id'] = $_GET["user_id"];
}
if( $_GET["device_id"] ) {
$data['device_id'] = $_GET["device_id"];
}
if( $_GET["app_version"] ) {
$data['app_version'] = $_GET["app_version"];
}
if( $_GET["os_name"] ) {
$data['os_name'] = $_GET["os_name"];
}
if( $_GET["os_version"] ) {
$data['os_version'] = $_GET["os_version"];
}
if( $_GET["device_model"] ) {
$data['device_model'] = $_GET["device_model"];
}
if( $_GET["country"] ) {
$data['country'] = $_GET["country"];
}
if( $_GET["language"] ) {
$data['language'] = $_GET["language"];
}
$data2 = array(
'api_key' => $_GET["api_key"],
'events' => $data
);
$url = "https://api2.amplitude.com/2/httpapi";
$ch = curl_init($url);
$payload = json_encode($data2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment