Skip to content

Instantly share code, notes, and snippets.

@kevinruscoe
Created September 11, 2015 11:34
Show Gist options
  • Save kevinruscoe/62c35fae406bafda7dc2 to your computer and use it in GitHub Desktop.
Save kevinruscoe/62c35fae406bafda7dc2 to your computer and use it in GitHub Desktop.
<?php
class GoogleCookieTools {
/**
* Splits Google's cookie into nicely named pairs
*
* @return array
* @author Kevin Ruscoe
*/
public static function splitCookie()
{
$output = array();
if( isset($_COOKIE['__utmz']) ){
$cookie = $_COOKIE['__utmz'];
$cookie_parts = explode("|", $cookie);
foreach( $cookie_parts as $cookie_part ){
$bits = explode("=", $cookie_part);
$key = $bits[0];
$value = $bits[1];
$key = preg_replace('/[0-9.]+/', '', $key);
// from: http://devblog.springest.com/anatomy-of-google-analytics-cookies/
$key = str_replace(
array(
'utmcsr', 'utmccn', 'utmcmd', 'utmcct'
),
array(
'Campaign Source', 'Compaign Name', 'Campaign Medium', 'Campaign Terms'
),
$key);
$output[$key] = $value;
}
}
return $output;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment