コード例 #1
0
 private function getQuery($profileId, $path)
 {
     $query = new Query($profileId);
     $query->setStartDate(new \DateTime('-1year'));
     $query->setEndDate(new \DateTime());
     // See https://developers.google.com/analytics/devguides/reporting/core/dimsmets
     $query->setMetrics(array('ga:visits', 'ga:bounceRate', 'ga:avgTimeOnPage'));
     $query->setDimensions(array('ga:pagePath'));
     // See https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters
     $query->setFilters(array('ga:pagePath=~^' . $path));
     return $query;
 }
コード例 #2
0
 public function test_init_analytics_instance()
 {
     $client = $this->prepareClientInstance();
     $profileId = 'ga:67356838';
     $query = new Query($profileId);
     $query->setStartDate(new \DateTime('-2months'));
     $query->setEndDate(new \DateTime());
     $query->setMetrics(array('ga:visits', 'ga:bounces'));
     $query->setDimensions(array('ga:browser', 'ga:city'));
     $service = new Service($client);
     $response = $service->query($query);
     var_dump($response);
 }
コード例 #3
0
 public function testBuild()
 {
     $this->query->setIds($ids = 'ids');
     $this->query->setStartDate($startDate = new \DateTime('2013-01-01'));
     $this->query->setEndDate($endDate = new \DateTime('2013-01-31'));
     $this->query->setMetrics($metrics = array('m1', 'm2'));
     $this->query->setDimensions($dimensions = array('d1', 'd2'));
     $this->query->setSorts(array('s1', 's2'));
     $this->query->setFilters(array('f1', 'f2'));
     $this->query->setSegment('seg');
     $this->query->setStartIndex(10);
     $this->query->setMaxResults(100);
     $this->query->setPrettyPrint(true);
     $this->query->setCallback('call');
     $expected = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ids&metrics=m1%2Cm2&start-date=2013-01-01&' . 'end-date=2013-01-31&access_token=token&start-index=10&max-results=100&segment=seg&dimensions=d1%2Cd2&' . 'filters=f1%2Cf2&sort=s1%2Cs2&prettyPrint=true&callback=call';
     $this->assertSame($expected, $this->query->build('token'));
 }