Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #14 from Kostanos/master
Browse files Browse the repository at this point in the history
Added Site Speed and Pageviews per Visit metrics
  • Loading branch information
danielmitd committed Jul 31, 2013
2 parents eff55a7 + 8befdf8 commit 0103e7c
Showing 1 changed file with 42 additions and 16 deletions.
58 changes: 42 additions & 16 deletions Zend/Gdata/Analytics/DataQuery.php
Expand Up @@ -131,6 +131,8 @@ class Zend_Gdata_Analytics_DataQuery extends Zend_Gdata_Query

// M1. Visitor
const METRIC_BOUNCES = 'ga:bounces';
const METRIC_VISIT_BOUNCE_RATE = 'ga:visitBounceRate';
const METRIC_ENTRANCE_BOUNCE_RATE = 'ga:entranceBounceRate';
const METRIC_ENTRANCES = 'ga:entrances';
const METRIC_EXITS = 'ga:exits';
const METRIC_NEW_VISITS = 'ga:newVisits';
Expand All @@ -140,6 +142,9 @@ class Zend_Gdata_Analytics_DataQuery extends Zend_Gdata_Query
const METRIC_VISITORS = 'ga:visitors';
const METRIC_VISITS = 'ga:visits';

// Page Tracking
const METRIC_PAGEVIEWS_PER_VISIT = 'ga:pageviewsPerVisit';

// M2. Campaign
const METRIC_AD_CLICKS = 'ga:adClicks';
const METRIC_AD_COST = 'ga:adCost';
Expand Down Expand Up @@ -181,7 +186,28 @@ class Zend_Gdata_Analytics_DataQuery extends Zend_Gdata_Query
const METRIC_TOTAL_EVENTS = 'ga:totalEvents';
const METRIC_UNIQUE_EVENTS = 'ga:uniqueEvents';
const METRIC_EVENT_VALUE = 'ga:eventValue';


// Site Speed
const METRIC_PAGE_LOAD_TIME = 'ga:pageLoadTime';
const METRIC_PAGE_LOAD_SAMPLE = 'ga:pageLoadSample';
const METRIC_AVG_PAGE_LOAD_TIME = 'ga:avgPageLoadTime';
const METRIC_DOMAIN_LOOKUP_TIME = 'ga:domainLookupTime';
const METRIC_AVG_DOMAIN_LOOKUP_TIME = 'ga:avgDomainLookupTime';
const METRIC_PAGE_DOWNLOAD_TIME = 'ga:pageDownloadTime';
const METRIC_AVG_PAGE_DOWNLOAD_TIME = 'ga:avgPageDownloadTime';
const METRIC_REDIRECTION_TIME = 'ga:redirectionTime';
const METRIC_AVG_REDIRECTION_TIME = 'ga:avgRedirectionTime';
const METRIC_SERVER_CONNECTION_TIME = 'ga:serverConnectionTime';
const METRIC_AVG_SERVER_CONNECTION_TIME = 'ga:avgServerConnectionTime';
const METRIC_SERVER_RESPONSE_TIME = 'ga:serverResponseTime';
const METRIC_AVG_SERVER_RESPONSE_TIME = 'ga:avgServerResponseTime';
const METRIC_SPEED_METRICS_SAMPLE = 'ga:speedMetricsSample';
const METRIC_DOM_INTERACTIVE_TIME = 'ga:domInteractiveTime';
const METRIC_AVG_DOM_INTERACTIVE_TIME = 'ga:avgDomInteractiveTime';
const METRIC_DOM_CONTENT_LOADED_TIME = 'ga:domContentLoadedTime';
const METRIC_AVG_DOMCONTENT_LOADED_TIME = 'ga:avgDomContentLoadedTime';
const METRIC_DOM_LATENCY_METRICS_SAMPLE = 'ga:domLatencyMetricsSample';

// suported filter operators
const EQUALS = "==";
const EQUALS_NOT = "!=";
Expand All @@ -193,7 +219,7 @@ class Zend_Gdata_Analytics_DataQuery extends Zend_Gdata_Query
const CONTAINS_NOT ="!@";
const REGULAR ="=~";
const REGULAR_NOT ="!~";

/**
* @var string
*/
Expand All @@ -214,7 +240,7 @@ class Zend_Gdata_Analytics_DataQuery extends Zend_Gdata_Query
* @var array
*/
protected $_filters = array();

/**
* @param string $id
* @return Zend_Gdata_Analytics_DataQuery
Expand All @@ -239,7 +265,7 @@ public function getProfileId()
*/
public function addDimension($dimension)
{
$this->_dimensions[$dimension] = true;
$this->_dimensions[$dimension] = true;
return $this;
}

Expand Down Expand Up @@ -305,7 +331,7 @@ public function setEndDate($date)
$this->setParam("end-date", $date);
return $this;
}

/**
* @param string $filter
* @return Zend_Gdata_Analytics_DataQuery
Expand All @@ -315,7 +341,7 @@ public function addFilter($filter)
$this->_filters[] = array($filter, true);
return $this;
}

/**
* @param string $filter
* @return Zend_Gdata_Analytics_DataQuery
Expand All @@ -325,7 +351,7 @@ public function addOrFilter($filter)
$this->_filters[] = array($filter, false);
return $this;
}

/**
* @param string $sort
* @param boolean[optional] $descending
Expand All @@ -337,7 +363,7 @@ public function addSort($sort, $descending=false)
$this->_sort[] = ($descending?'-':'').$sort;
return $this;
}

/**
* @return Zend_Gdata_Analytics_DataQuery
*/
Expand All @@ -346,7 +372,7 @@ public function clearSort()
$this->_sort = array();
return $this;
}

/**
* @param string $segment
* @return Zend_Gdata_Analytics_DataQuery
Expand All @@ -366,37 +392,37 @@ public function getQueryUrl()
if (isset($this->_url)) {
$uri = $this->_url;
}

$dimensions = $this->getDimensions();
if (!empty($dimensions)) {
$this->setParam('dimensions', implode(",", array_keys($dimensions)));
}

$metrics = $this->getMetrics();
if (!empty($metrics)) {
$this->setParam('metrics', implode(",", array_keys($metrics)));
}

// profile id (ga:tableId)
if ($this->getProfileId() != null) {
$this->setParam('ids', 'ga:'.ltrim($this->getProfileId(), "ga:"));
}

// sorting
if ($this->_sort) {
$this->setParam('sort', implode(",", $this->_sort));
}

// filtering
$filters = "";
foreach ($this->_filters as $filter) {
$filters.=($filter[1]===true?';':',').$filter[0];
}

if ($filters!="") {
$this->setParam('filters', ltrim($filters, ",;"));
}

$uri .= $this->getQueryString();
return $uri;
}
Expand Down

0 comments on commit 0103e7c

Please sign in to comment.