Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for combining manual and autotagging #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions class.gaparse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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);
Expand All @@ -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;


Expand Down