Posted in PHP 12 years ago 3 min read
define('ga_email','email@anda');
define('ga_password','password');
define('ga_profile_id','id_profile');
Data tersebut berbeda-beda tergantung dari website anda masing-masing.
[caption id="" align="aligncenter" width="325"]
Filter Browser dan Negara[/caption]
$filter = 'browser == Firefox || browser == Chrome || browser == Opera || browser == Safari || browser == Internet Explorer';Kemudian ubah juga requestDatanya
$ga->requestReportData(ga_profile_id,array('browser'),array('visits'),'-visits',$filter);
Tabel untuk menampilkan hasil query GAPI.
<table> <tr> <th>Browser</th> <th>Visits</th> </tr> <?php foreach($ga->getResults() as $result): ?> <tr> <td><?php echo $result ?></td> <td><?php echo $result->getVisits() ?></td> </tr> <?php endforeach ?> </table>
<?php
define('ga_email','email@gmail.com');
define('ga_password','password');
define('ga_profile_id','id_profile');
require 'gapi.class.php';
$ga = new gapi(ga_email,ga_password);
$filter = 'browser == Firefox || browser == Chrome || browser == Opera || browser == Safari || browser == Internet Explorer';
$ga->requestReportData(ga_profile_id,array('browser'),array('visits'),'-visits',$filter);
?>
<table>
<tr>
<th>Browser</th>
<th>Visits</th>
</tr>
<?php
foreach($ga->getResults() as $result):
?>
<tr>
<td><?php echo $result ?></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 Visits</th>
<td><?php echo $ga->getVisits() ?></td>
</tr>
<tr>
<th>Results Updated</th>
<td><?php echo $ga->getUpdated() ?></td>
</tr>
</table>
[caption id="" align="aligncenter" width="312"]
Visitor by Browser[/caption]
Semoga bermanfaat.