Skip to content

Instantly share code, notes, and snippets.

@walkergv
Last active May 20, 2022 09:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save walkergv/9844637 to your computer and use it in GitHub Desktop.
Save walkergv/9844637 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