Skip to content

Instantly share code, notes, and snippets.

@kibal4iw
Forked from walkergv/php-UA.php
Last active August 29, 2015 14:25
Show Gist options
  • Save kibal4iw/1118f4f87e6e87fe77a7 to your computer and use it in GitHub Desktop.
Save kibal4iw/1118f4f87e6e87fe77a7 to your computer and use it in GitHub Desktop.
Simple Event Tracking with Measurement Protocol Using cURL and PHP (plus redirect)
<?
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www.google-analytics.com/collect?v=1&tid=[UA-XXXXXXXXX-1]&cid=[RANDOM_INTEGER_OR_GUID]&t=event&ec=[EVENT_CATEGORY]&ea=[EVENT_ACTION]&el=[EVENT_LABEL]',
CURLOPT_USERAGENT => 'Vanity-URL-Tracker',
));
$resp = curl_exec($curl);
curl_close($curl);
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.reddit.com/");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment