-
Notifications
You must be signed in to change notification settings - Fork 13
/
fetch_ga.php
32 lines (27 loc) · 892 Bytes
/
fetch_ga.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
<?php
require_once('lib/gapi.class.php');
require_once('inc/db.php');
require_once('inc/helper.php');
require_once('inc/fetch.php');
$fetchGA = true;
$saveToDB = true;
echo 'Start fetch GA: '.date("Y-m-d H:i:s").'<br>';
foreach ($accounts as $account) {
echo 'Get stat for: '.$account['url'].' - '.date("Y-m-d H:i:s").'<br>';
if ($fetchGA) {
if ($account['ga_username'] != '') {
$ga = new gapi($account['ga_username'],$account['ga_passwd']);
$fromDate = date("Y-m-d", strtotime('-6 days'));
$toDate = date("Y-m-d");
$ga->requestReportData($account['ga_profileid'], array('week','date','hour'), array('pageviews','visits'), array('date'), null, $fromDate, $toDate, 1, 1000);
foreach($ga->getResults() as $result) {
//01 20100101 00
if ($saveToDB) {
saveGAStat($account,$result);
}
}
}
}
}
echo 'End fetch GA: '.date("Y-m-d H:i:s").'<br>';
?>