forked from lobsterdore/analytics-api-oauth2-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmostPopularContentExample.php
More file actions
41 lines (31 loc) · 1.23 KB
/
mostPopularContentExample.php
File metadata and controls
41 lines (31 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
// api dependencies
// svn checkout http://google-api-php-client.googlecode.com/svn/trunk/ google-api-php-client-read-only
require_once('google-api-php-client-read-only/src/Google_Client.php');
require_once('google-api-php-client-read-only/src/contrib/Google_AnalyticsService.php');
// create client object and set app name
$client = new Google_Client();
$client->setApplicationName('Most popular'); // name of your app
// set assertion credentials
$client->setAssertionCredentials(
new Google_AssertionCredentials(
'', // email you added to GA
array('http://www.googleapis.com/auth/analytics.readonly'),
file_get_contents('') // keyfile you downloaded
));
// other settings
$client->setClientId(''); // from API console
// create service and get data
$service = new Google_AnalyticsService($client);
$response = $service->data_ga->get(
'', // profile id
'2012-08-01', // start date
'2012-09-16', // end date
'ga:uniquePageviews',
array(
'dimensions' => 'ga:pagePath',
'sort' => '-ga:uniquePageviews',
'filters' => 'ga:pagePath=~\/[a-zA-Z0-9\-]+\/[a-zA-Z0-9\-]+', // example url filter
'max-results' => '25'));
var_dump($response);
?>