Posted in PHP
<?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); $ga->requestReportData(ga_profile_id,array('browser','browserVersion'),array('pageviews','visits')); ?> <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>Perhatikan code berikut dari example.report.php
define('ga_email','youremail@email.com'); //ubah sesuai dengan email anda define('ga_password','your password'); //ubah sesuai password email anda define('ga_profile_id','your profile id'); //ubah dengan id profile Google Analytics andaCode di atas adalah konfigurasi yang harus anda ubah untuk dapat menampilkan data website menggunakan GAPI. Untuk bagian your profile id adalah id dari website di Google Analytics anda, berupa beberapa digit angka seperti 51378101. Profile id inilah yang menentukan statistik website mana yang ditampilkan oleh GAPI. Jika anda merasa bingung anda dapat membaca post saya di Menentukan Profile Id Google Analytics.