Skip to content

Instantly share code, notes, and snippets.

@dublado
Created April 2, 2012 20:24
Show Gist options
  • Save dublado/2286973 to your computer and use it in GitHub Desktop.
Save dublado/2286973 to your computer and use it in GitHub Desktop.
get utm source, name and all
function getUtm(){
$utm = array();
if(!empty($_COOKIE['__utmz'])){
$pattern = "/(utmcsr=([^\|]*)[\|]?)|(utmccn=([^\|]*)[\|]?)|(utmcmd=([^\|]*)[\|]?)|(utmctr=([^\|]*)[\|]?)|(utmcct=([^\|]*)[\|]?)/i";
preg_match_all($pattern, $_COOKIE['__utmz'], $matches);
if(!empty($matches[0])){
foreach($matches[0] as $match){
$pair = null;
$match = trim($match, "|");
list($k, $v) = explode("=", $match);
$utm[$k] = $v;
}
}
}
return $utm;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment