diff --git a/src/Widop/GoogleAnalytics/Query.php b/src/Widop/GoogleAnalytics/Query.php index 028a18e..129c2f1 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. * @@ -533,6 +570,9 @@ public function build($accessToken) 'start-index' => $this->getStartIndex(), 'max-results' => $this->getMaxResults(), ); + if ($this->hasSamplingLevel()) { + $query['samplingLevel'] = $this->getSamplingLevel(); + } if ($this->hasSegment()) { $query['segment'] = $this->getSegment();