-
Notifications
You must be signed in to change notification settings - Fork 86
/
example.filter.php
59 lines (54 loc) · 1.43 KB
/
example.filter.php
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require 'gapi.class.php';
define('ga_profile_id','your profile id');
$ga = new gapi("XXXXXXXX@developer.gserviceaccount.com", "key.p12");
/**
* Note: OR || operators are calculated first, before AND &&.
* There are no brackets () for precedence and no quotes are
* required around parameters.
*
* Do not use brackets () for precedence, these are only valid for
* use in regular expressions operators!
*
* The below filter represented in normal PHP logic would be:
* country == 'United States' && ( browser == 'Firefox || browser == 'Chrome')
*/
$filter = 'country == United States && browser == Firefox || browser == Chrome';
$ga->requestReportData(ga_profile_id,array('browser','browserVersion'),array('pageviews','visits'),'-visits',$filter);
?>
<table>
<tr>
<th>Browser & Browser Version</th>
<th>Pageviews</th>
<th>Visits</th>
</tr>
<?php
foreach($ga->getResults() as $result):
?>
<tr>
<td><?php echo $result ?></td>
<td><?php echo $result->getPageviews() ?></td>
<td><?php echo $result->getVisits() ?></td>
</tr>
<?php
endforeach
?>
</table>
<table>
<tr>
<th>Total Results</th>
<td><?php echo $ga->getTotalResults() ?></td>
</tr>
<tr>
<th>Total Pageviews</th>
<td><?php echo $ga->getPageviews() ?>
</tr>
<tr>
<th>Total Visits</th>
<td><?php echo $ga->getVisits() ?></td>
</tr>
<tr>
<th>Result Date Range</th>
<td><?php echo $ga->getStartDate() ?> to <?php echo $ga->getEndDate() ?></td>
</tr>
</table>