01.
<?php
02.
define(
'ga_email'
,
'google_analytics_google_email@domain.com'
);
03.
define(
'ga_password'
,
'your_Google_Analytics_password'
);
04.
define(
'ga_profile_id'
,
'YOUR GOOGLE ANALYTICS PROFILE ID'
);
05.
06.
require
'gapi.class.php'
;
07.
08.
$ga
=
new
gapi(ga_email,ga_password);
09.
10.
$today
=
date
(
'Y-m-d'
);
11.
$search
=
array
(
"2009"
,
"2010"
,
"01"
,
"02"
,
"03"
,
"04"
,
"05"
,
"06"
,
"07"
,
"08"
,
"09"
,
"10"
,
"11"
,
"12"
);
12.
$replace
=
array
(
""
,
""
,
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
);
13.
$search2
=
array
(
"<"
);
14.
$replace2
=
array
(
""
);
15.
16.
$ga
->requestReportData(ga_profile_id,
array
(
'month'
,
'year'
),
array
(
'pageviews'
,
'visits'
,
'bounces'
,
'entrances'
),
array
(
'-year'
,
'-month'
) ,
$filter
=null,
$start_date
=
'2009-03-01'
,
$end_date
=
$today
,
$start_index
=1,
$max_results
=1000);
17.
?>
18.
<table width=
"99%"
align=
"center"
>
19.
<tr>
20.
<th>Month</th>
21.
<th>Year</th>
22.
<th>Pageviews</th>
23.
<th>Visits</th>
24.
</tr>
25.
<?php
26.
foreach
(
$ga
->getResults()
as
$result
):
27.
?>
28.
<tr valign=
"center"
align=
"center"
>
29.
<td width=
"25%"
><?php
echo
str_replace
(
$search
,
$replace
,
$result
) ?></td>
30.
<td width=
"20%"
><?php
echo
$result
->getYear(
str_replace
(
$search2
,
$replace2
,
$result
)) ?>
31.
<td width=
"30%"
><?php
echo
$result
->getPageviews() ?></td>
32.
<td width=
"25%"
><?php
echo
$result
->getVisits() ?></td>
33.
</tr>
34.
<?php
35.
endforeach
36.
?>
37.
</table>
38.
<br/><br/>
39.
<table>
40.
<tr>
41.
<th>Total Months:</th>
42.
<td><?php
echo
$ga
->getTotalResults() ?></td>
43.
</tr>
44.
<tr>
45.
<th>Total Pageviews</th>
46.
<td><?php
echo
$ga
->getPageviews() ?>
47.
</tr>
48.
<tr>
49.
<th>Total Visits</th>
50.
<td><?php
echo
$ga
->getVisits() ?></td>
51.
</tr>
52.
<tr>
53.
<th>Results Updated</th>
54.
<td><?php
echo
$ga
->getUpdated() ?></td>
55.
</tr>
56.
</table>