File: Zend_Gdata_Analytics.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (76 lines) | stat: -rw-r--r-- 3,346 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.gdata.analytics">
    <title>Using Google Analytics</title>

    <para>
        The Google Analytics <acronym>API</acronym> allows client applications to 
        request data, saved in the analytics accounts.
    </para>

    <para>
        See <ulink
            url="http://code.google.com/apis/analytics/docs/gdata/v2/gdataOverview.html">http://code.google.com/apis/analytics/docs/gdata/v2/gdataOverview.html</ulink>
        for more information about the Google Analytics <acronym>API</acronym>.
    </para>

    <sect2 id="zend.gdata.analytics.accounts">
        <title>Retrieving account data</title>

        <para>
           Using the account feed, you are able to retrieve a list of all the accounts available to a specified user.  
        </para>

        <programlisting language="php"><![CDATA[
$service = Zend_Gdata_Analytics::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $password, $service);
$analytics = new Zend_Gdata_Analytics($client);  
$accounts = $analytics->getAccountFeed();

foreach ($accounts as $account) {  
  echo "\n{$account->title}\n";
}
]]></programlisting>

        <para>
            The <command>$analytics->getAccountFeed()</command> call, results in a 
            <classname>Zend_Gdata_Analytics_AccountFeed</classname> object that  contains
            <classname>Zend_Gdata_Analytics_AccountEntry</classname> objects. Each of this
            objects represent a google analytics account.
        </para>
    </sect2>

    <sect2 id="zend.gdata.analytics.reports">
        <title>Retrieving report data</title>

        <para>
            Besides the account feed, google offers a data feed, to retrieve report data using
            the Google Analytics <acronym>API</acronym>. To easily request for these reports,
            Zend_Gdata_Analytics offers a simple query construction interface. You can use all
            the <ulink url="http://code.google.com/intl/de-CH/apis/analytics/docs/gdata/dimsmets/dimsmets.html">metrics
            and dimensions</ulink> specified by the API. Additionaly you can apply some <ulink url="http://code.google.com/intl/de-CH/apis/analytics/docs/gdata/v2/gdataReferenceDataFeed.html#filters">filters</ulink>
            to retrieve some <ulink url="http://code.google.com/intl/de-CH/apis/analytics/docs/gdata/gdataCommonQueries.html">common
            data</ulink> or even complex results.
        </para>

        <programlisting language="php"><![CDATA[
$query = $service->newDataQuery()->setProfileId($profileId)  
  ->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_BOUNCES)   
  ->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_VISITS) 
  ->addDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_MEDIUM)  
  ->addDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_SOURCE)  
  ->addFilter("ga:browser==Firefox")  
  ->setStartDate('2011-05-01')   
  ->setEndDate('2011-05-31')   
  ->addSort(Zend_Gdata_Analytics_DataQuery::METRIC_VISITS, true)  
  ->addSort(Zend_Gdata_Analytics_DataQuery::METRIC_BOUNCES, false)  
  ->setMaxResults(50); 
  
$result = $analytics->getDataFeed($query);
foreach($result as $row){  
  echo $row->getMetric('ga:visits')."\t";  
  echo $row->getValue('ga:bounces')."\n";  
}
]]></programlisting>
    </sect2>
</sect1>