From 183323268399a34065040f3e16cdbe18b21df8b5 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 1 May 2014 16:54:07 +0100 Subject: [PATCH 1/3] Added sampling level --- src/Widop/GoogleAnalytics/Query.php | 56 ++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/src/Widop/GoogleAnalytics/Query.php b/src/Widop/GoogleAnalytics/Query.php index 028a18e..a330bb1 100644 --- a/src/Widop/GoogleAnalytics/Query.php +++ b/src/Widop/GoogleAnalytics/Query.php @@ -57,6 +57,9 @@ class Query /** @var string */ protected $callback; + /** @var string */ + protected $samplingLevel; + /** * Creates a google analytics query. * @@ -515,6 +518,40 @@ public function setCallback($callback) return $this; } + /** + * Checks the google analytics query for a sampling level. + * + * @return boolean TRUE if the google analytics query has a sampling level else FALSE. + */ + public function hasSamplingLevel() + { + return !empty($this->samplingLevel); + } + + /** + * Gets the google analytics query sampling level. + * + * @return string The google analytics sampling level ('FASTER', DEFAULT', 'HIGHER_PRECISION'). + */ + public function getSamplingLevel() + { + return $this->samplingLevel; + } + + /** + * Sets the google analytics query sampling level. + * + * @param string $samplingLevel The google analytics query sampling level ('FASTER', DEFAULT', 'HIGHER_PRECISION'). + * + * @return \Widop\GoogleAnalytics\Query The query. + */ + public function setSamplingLevel($samplingLevel) + { + $this->samplingLevel = $samplingLevel; + + return $this; + } + /** * Builds the query. * @@ -525,14 +562,17 @@ public function setCallback($callback) public function build($accessToken) { $query = array( - 'ids' => $this->getIds(), - 'metrics' => implode(',', $this->getMetrics()), - 'start-date' => $this->getStartDate()->format('Y-m-d'), - 'end-date' => $this->getEndDate()->format('Y-m-d'), - 'access_token' => $accessToken, - 'start-index' => $this->getStartIndex(), - 'max-results' => $this->getMaxResults(), + 'ids' => $this->getIds(), + 'metrics' => implode(',', $this->getMetrics()), + 'start-date' => $this->getStartDate()->format('Y-m-d'), + 'end-date' => $this->getEndDate()->format('Y-m-d'), + 'access_token' => $accessToken, + 'start-index' => $this->getStartIndex(), + 'max-results' => $this->getMaxResults(), ); + if ($this->hasSamplingLevel()) { + $query['samplingLevel'] = $this->getSamplingLevel(); + } if ($this->hasSegment()) { $query['segment'] = $this->getSegment(); @@ -557,7 +597,7 @@ public function build($accessToken) if ($this->hasCallback()) { $query['callback'] = $this->getCallback(); } - + var_dump(sprintf('%s?%s', self::URL, http_build_query($query))); return sprintf('%s?%s', self::URL, http_build_query($query)); } } From 29b877d6f2cde7e4b3ea46669e5825c39d5812c6 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 1 May 2014 16:57:47 +0100 Subject: [PATCH 2/3] removed var_dump :S --- src/Widop/GoogleAnalytics/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widop/GoogleAnalytics/Query.php b/src/Widop/GoogleAnalytics/Query.php index a330bb1..05bcbd0 100644 --- a/src/Widop/GoogleAnalytics/Query.php +++ b/src/Widop/GoogleAnalytics/Query.php @@ -597,7 +597,7 @@ public function build($accessToken) if ($this->hasCallback()) { $query['callback'] = $this->getCallback(); } - var_dump(sprintf('%s?%s', self::URL, http_build_query($query))); + return sprintf('%s?%s', self::URL, http_build_query($query)); } } From dfca3740749c36dda23843b6cf9d1d970c0337f9 Mon Sep 17 00:00:00 2001 From: sitapson Date: Thu, 1 May 2014 17:13:10 +0100 Subject: [PATCH 3/3] Removed whitespace. My bad. --- src/Widop/GoogleAnalytics/Query.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Widop/GoogleAnalytics/Query.php b/src/Widop/GoogleAnalytics/Query.php index 05bcbd0..129c2f1 100644 --- a/src/Widop/GoogleAnalytics/Query.php +++ b/src/Widop/GoogleAnalytics/Query.php @@ -562,13 +562,13 @@ public function setSamplingLevel($samplingLevel) public function build($accessToken) { $query = array( - 'ids' => $this->getIds(), - 'metrics' => implode(',', $this->getMetrics()), - 'start-date' => $this->getStartDate()->format('Y-m-d'), - 'end-date' => $this->getEndDate()->format('Y-m-d'), - 'access_token' => $accessToken, - 'start-index' => $this->getStartIndex(), - 'max-results' => $this->getMaxResults(), + 'ids' => $this->getIds(), + 'metrics' => implode(',', $this->getMetrics()), + 'start-date' => $this->getStartDate()->format('Y-m-d'), + 'end-date' => $this->getEndDate()->format('Y-m-d'), + 'access_token' => $accessToken, + 'start-index' => $this->getStartIndex(), + 'max-results' => $this->getMaxResults(), ); if ($this->hasSamplingLevel()) { $query['samplingLevel'] = $this->getSamplingLevel();