From ceb1bf05fc77c19a2ca0b3c0b693d4aa25eb3f75 Mon Sep 17 00:00:00 2001 From: Anthony DiSanti Date: Fri, 20 Feb 2015 15:46:25 -0500 Subject: [PATCH] Adds support for combining manual and autotagging * Changes logic for inferring AdWords parameters to only fill empty parameters and not overwrite any values with blanks * Changes double quotes to single quotes --- class.gaparse.php | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/class.gaparse.php b/class.gaparse.php index e5bdaf2..9ba4d52 100644 --- a/class.gaparse.php +++ b/class.gaparse.php @@ -34,7 +34,7 @@ class GA_Parse function __construct($_COOKIE) { // If we have the cookies we can go ahead and parse them. - if (isset($_COOKIE["__utma"]) and isset($_COOKIE["__utmz"])) { + if (isset($_COOKIE['__utma']) and isset($_COOKIE['__utmz'])) { $this->ParseCookies(); } @@ -43,31 +43,26 @@ function __construct($_COOKIE) { function ParseCookies(){ // Parse __utmz cookie - list($domain_hash,$timestamp, $session_number, $campaign_numer, $campaign_data) = preg_split('[\.]', $_COOKIE["__utmz"],5); + list($domain_hash,$timestamp, $session_number, $campaign_numer, $campaign_data) = preg_split('[\.]', $_COOKIE['__utmz'],5); // Parse the campaign data - $campaign_data = parse_str(strtr($campaign_data, "|", "&")); + $campaign_data = parse_str(strtr($campaign_data, '|', '&')); $this->campaign_source = $utmcsr; $this->campaign_name = $utmccn; $this->campaign_medium = $utmcmd; - if (isset($utmctr)) $this->campaign_term = $utmctr; - if (isset($utmcct)) $this->campaign_content = $utmcct; + $this->campaign_term = (isset($utmctr) ? $utmctr : ''); + $this->campaign_content = (isset($utmcct) ? $utmcct : ''); - // You should tag you campaigns manually to have a full view - // of your adwords campaigns data. - // The same happens with Urchin, tag manually to have your campaign data parsed properly. - + // If auto-tagging has been enabled in Google AdWords, we can infer some + // campaign parameters if they weren't defined manually if (isset($utmgclid)) { - $this->campaign_source = "google"; - $this->campaign_name = ""; - $this->campaign_medium = "cpc"; - $this->campaign_content = ""; - $this->campaign_term = $utmctr; + if (!isset($utmcsr)) $this->campaign_source = 'google'; + if (!isset($utmcmd)) $this->campaign_medium = 'cpc'; } // Parse the __utma Cookie - list($domain_hash,$random_id,$time_initial_visit,$time_beginning_previous_visit,$time_beginning_current_visit,$session_counter) = preg_split('[\.]', $_COOKIE["__utma"]); + list($domain_hash,$random_id,$time_initial_visit,$time_beginning_previous_visit,$time_beginning_current_visit,$session_counter) = preg_split('[\.]', $_COOKIE['__utma']); $this->first_visit = new \DateTime(); $this->first_visit->setTimestamp($time_initial_visit); @@ -82,7 +77,7 @@ function ParseCookies(){ // Parse the __utmb Cookie - list($domain_hash,$pages_viewed,$garbage,$time_beginning_current_session) = preg_split('[\.]', $_COOKIE["__utmb"]); + list($domain_hash,$pages_viewed,$garbage,$time_beginning_current_session) = preg_split('[\.]', $_COOKIE['__utmb']); $this->pages_viewed = $pages_viewed;