Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor fix to sort parameter, add ga: prefix to string parameter passe…
…d (not array) and handle reverse sort New 'filter' functionality - New $filter parameter on requestReportData between sort and start_date - may cause problems with existing implementations of gapi.class.php but this is the best place... New filter process function to clean up the parameters and translate to Google Analytics compatible filters string. New example showing use of filter.
- Loading branch information
Showing
2 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
define('ga_email','youremail@email.com'); | ||
define('ga_password','your password'); | ||
define('ga_profile_id','your profile id'); | ||
|
||
require 'gapi.class.php'; | ||
|
||
$ga = new gapi(ga_email,ga_password); | ||
|
||
/** | ||
* 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>Results Updated</th> | ||
<td><?php echo $ga->getUpdated() ?></td> | ||
</tr> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters