Extracting campaign data from Google Analytics cookies

Google Analytics in the last couple of years became a standard tool for web analytics as well a statndard tool for tracking marketing campaign. when a visitor hits first time your site Google Analytics sets different types of cookies in the visitors browser, one of these cookies is called utmz. this cookie holds quite valuable information like campaign name, campaign source, campaign medium, campaign term and campaign content.

to extract this data I used the following PHP method :

function getUtm(){
    $utm = array();
        $pattern = "/(utmcsr=([^\|]*)[\|]?)|(utmccn=([^\|]*)[\|]?)|(utmcmd=([^\|]*)[\|]?)|(utmctr=([^\|]*)[\|]?)|(utmcct=([^\|]*)[\|]?)/i";
        preg_match_all($pattern, $_COOKIE['__utmz'], $matches);
            foreach($matches[0] as $match){
                $pair = null;
                $match = trim($match, "|");
                list($k, $v) = explode("=", $match);
                $utm[$k] = $v;
    return $utm;

the returned array from this method will contain the following:
utmccn => campaign name
utmcsr => campaign source
utmcmd => campaign medium
utmctr => campaign term or keyword
utmcct => campaign content