Browse Source

add Zend_Gdata_Analytics

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24682 44c647ce-9c0f-0410-b52a-842ac1e357ba
danielMitD 14 years ago
parent
commit
5a4ca7c3c6

+ 7 - 0
documentation/manual/de/module_specs/Zend_Gdata-Introduction.xml

@@ -80,6 +80,13 @@
                     Photo Sharing Anwendung.
                 </para>
             </listitem>
+            
+            <listitem>
+                <para>
+                    <link linkend="zend.gdata.analytics">Google Analytics</link>
+                    bietet eine Besucher-Analyse Anwendung.
+                </para>
+            </listitem>
 
             <listitem>
                 <para>

+ 77 - 0
documentation/manual/de/module_specs/Zend_Gdata_Analytics.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- EN-Revision: TBD -->
+<!-- Reviewed: no -->
+<sect1 id="zend.gdata.analytics">
+    <title>Verwenden der Google Analytics API</title>
+
+    <para>
+        Die Google Analytics <acronym>API</acronym> erlaubt es Client-Anwendungen 
+        Daten aus Google Analytics Konten abzufragen.
+    </para>
+
+    <para>
+        Siehe <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>
+        für weitere Informationen über die Google Analytics <acronym>API</acronym>.
+    </para>
+
+    <sect2 id="zend.gdata.analytics">
+        <title>Account-Daten abfragen</title>
+
+        <para>
+           Der Account-Feed gibt eine Übersicht über alle Konten und deren Properties.  
+        </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>
+            Die Rückgabe der Method <command>$analytics->getAccountFeed()</command>, ein Objekt
+            der Klasse <classname>Zend_Gdata_Analytics_AccountFeed</classname>, beinhaltet eine
+            Liste von <classname>Zend_Gdata_Analytics_AccountEntry</classname> Objekten. Diese
+            Objekte bilden die jeweiligen Properties innerhalb des Accounts ab.
+        </para>
+    </sect2>
+
+    <sect2 id="zend.gdata.analytics.datafeed">
+        <title>Statistische Daten abfragen</title>
+
+        <para>
+            Neben dem Account-Feed besteht auch die Möglichkeit, die statistischen Daten der 
+            einzelnen Accounts abzufragen. Hierfür steht eine vereinfacht Abfrage-Syntax zur
+            Verfügung, welche das Erstellen der URL-Abfragen vereinfacht. Hierbei stehen die
+            von Google bereitgestellten <ulink url="http://code.google.com/intl/de-CH/apis/analytics/docs/gdata/dimsmets/dimsmets.html">Metriken
+            bzw. Dimensionen</ulink> zur Verfügung. Mit diesen und einer Anzahl an <ulink url="http://code.google.com/intl/de-CH/apis/analytics/docs/gdata/v2/gdataReferenceDataFeed.html#filters">
+            Filtern</ulink> können neben <ulink url="http://code.google.com/intl/de-CH/apis/analytics/docs/gdata/gdataCommonQueries.html">gewöhnlichen
+            Werten</ulink> auch komplexre Resultate abgefrage werden.
+        </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>

+ 5 - 0
documentation/manual/en/manual.xml.in

@@ -1035,6 +1035,11 @@
                     <xi:include href="../en/module_specs/Zend_Gdata-Introduction.xml" />
                 </xi:fallback>
             </xi:include>
+            <xi:include href="module_specs/Zend_Gdata_Analytics.xml">
+                <xi:fallback>
+                    <xi:include href="../en/module_specs/Zend_Gdata_Analytics.xml" />
+                </xi:fallback>
+            </xi:include>
             <xi:include href="module_specs/Zend_Gdata_AuthSub.xml">
                 <xi:fallback>
                     <xi:include href="../en/module_specs/Zend_Gdata_AuthSub.xml" />

+ 7 - 0
documentation/manual/en/module_specs/Zend_Gdata-Introduction.xml

@@ -81,6 +81,13 @@
                     provides an online photo sharing application.
                 </para>
             </listitem>
+            
+            <listitem>
+                <para>
+                    <link linkend="zend.gdata.analytics">Google Analytics</link>
+                    is a visitor statistics application.
+                </para>
+            </listitem>
 
             <listitem>
                 <para>

+ 76 - 0
documentation/manual/en/module_specs/Zend_Gdata_Analytics.xml

@@ -0,0 +1,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>

+ 122 - 0
library/Zend/Gdata/Analytics.php

@@ -0,0 +1,122 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Gdata
+ */
+require_once 'Zend/Gdata.php';
+
+/**
+ * @see Zend_Gdata_Analytics_AccountEntry
+ */
+require_once 'Zend/Gdata/Analytics/AccountEntry.php';
+
+/**
+ * @see Zend_Gdata_Analytics_AccountFeed
+ */
+require_once 'Zend/Gdata/Analytics/AccountFeed.php';
+
+/**
+ * @see Zend_Gdata_Analytics_DataEntry
+ */
+require_once 'Zend/Gdata/Analytics/DataEntry.php';
+
+/**
+ * @see Zend_Gdata_Analytics_DataFeed
+ */
+require_once 'Zend/Gdata/Analytics/DataFeed.php';
+
+/**
+ * @see Zend_Gdata_Analytics_DataQuery
+ */
+require_once 'Zend/Gdata/Analytics/DataQuery.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ */
+class Zend_Gdata_Analytics extends Zend_Gdata
+{
+
+	const AUTH_SERVICE_NAME = 'analytics';
+	const ANALYTICS_FEED_URI = 'https://www.google.com/analytics/feeds';
+	const ANALYTICS_ACCOUNT_FEED_URI = 'https://www.google.com/analytics/feeds/accounts';
+
+	public static $namespaces = array(
+        array('ga', 'http://schemas.google.com/analytics/2009', 1, 0)
+    );
+
+    /**
+     * Create Gdata object
+     *
+     * @param Zend_Http_Client $client
+     * @param string $applicationId The identity of the app in the form of
+     *          Company-AppName-Version
+     */
+    public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
+    {
+        $this->registerPackage('Zend_Gdata_Analytics');
+        $this->registerPackage('Zend_Gdata_Analytics_Extension');
+        parent::__construct($client, $applicationId);
+        $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
+    }
+
+    /**
+     * Retrieve account feed object
+     *
+     * @return Zend_Gdata_Analytics_AccountFeed
+     */
+    public function getAccountFeed()
+    {
+        $uri = self::ANALYTICS_ACCOUNT_FEED_URI . '/default?prettyprint=true';
+        return parent::getFeed($uri, 'Zend_Gdata_Analytics_AccountFeed');
+    }
+
+    /**
+     * Retrieve data feed object
+     * 
+     * @param mixed $location
+     * @return Zend_Gdata_Analytics_DataFeed
+     */
+    public function getDataFeed($location)
+    {
+		if ($location == null) {
+            $uri = self::ANALYTICS_FEED_URI;
+        } elseif ($location instanceof Zend_Gdata_Query) {
+            $uri = $location->getQueryUrl();
+        } else {
+            $uri = $location;
+        }
+        return parent::getFeed($uri, 'Zend_Gdata_Analytics_DataFeed');
+    }
+
+    /**
+     * Returns a new DataQuery object.
+     * 
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function newDataQuery()
+    {
+    	return new Zend_Gdata_Analytics_DataQuery();
+    }
+}

+ 95 - 0
library/Zend/Gdata/Analytics/AccountEntry.php

@@ -0,0 +1,95 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Gdata_Entry
+ */
+require_once 'Zend/Gdata/Entry.php';
+
+/**
+ * @see Zend_Gdata_Analytics_Extension_Dimension
+ */
+require_once 'Zend/Gdata/Analytics/Extension/Dimension.php';
+
+/**
+ * @see Zend_Gdata_Analytics_Extension_Metric
+ */
+require_once 'Zend/Gdata/Analytics/Extension/Metric.php';
+
+/**
+ * @see Zend_Gdata_Analytics_Extension_Property
+ */
+require_once 'Zend/Gdata/Analytics/Extension/Property.php';
+
+/**
+ * @see Zend_Gdata_Analytics_Extension_TableId
+ */
+require_once 'Zend/Gdata/Analytics/Extension/TableId.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ */
+class Zend_Gdata_Analytics_AccountEntry extends Zend_Gdata_Entry
+{
+	protected $_accountId;
+	protected $_accountName;
+	protected $_profileId;
+	protected $_webPropertyId;
+	protected $_currency;
+	protected $_timezone;
+	protected $_tableId;
+
+	/**
+	 * @see Zend_Gdata_Entry::__construct()
+	 */
+	public function __construct($element = null)
+    {
+        $this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces);
+        parent::__construct($element);
+    }
+
+    /**
+     * @param DOMElement $child
+     * @return void
+     */
+    protected function takeChildFromDOM($child)
+    {
+        $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
+        switch ($absoluteNodeName){
+        	case $this->lookupNamespace('ga') . ':' . 'property';
+	            $property = new Zend_Gdata_Analytics_Extension_Property();
+	            $property->transferFromDOM($child);
+	            $this->{$property->getName()} = $property;
+                break;
+        	case $this->lookupNamespace('ga') . ':' . 'tableId';
+	            $tableId = new Zend_Gdata_Analytics_Extension_TableId();
+	            $tableId->transferFromDOM($child);
+	            $this->_tableId = $tableId;
+                break;
+        	default:
+            	parent::takeChildFromDOM($child);
+                break;
+        }
+    }
+}

+ 57 - 0
library/Zend/Gdata/Analytics/AccountFeed.php

@@ -0,0 +1,57 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Gdata_Feed
+ */
+require_once 'Zend/Gdata/Feed.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ */
+class Zend_Gdata_Analytics_AccountFeed extends Zend_Gdata_Feed
+{
+    /**
+     * The classname for individual feed elements.
+     *
+     * @var string
+     */
+    protected $_entryClassName = 'Zend_Gdata_Analytics_AccountEntry';
+
+    /**
+     * The classname for the feed.
+     *
+     * @var string
+     */
+    protected $_feedClassName = 'Zend_Gdata_Analytics_AccountFeed';
+
+    /**
+     * @see Zend_GData_Feed::__construct()
+     */
+    public function __construct($element = null)
+    {
+        $this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces);
+        parent::__construct($element);
+    }
+}

+ 116 - 0
library/Zend/Gdata/Analytics/DataEntry.php

@@ -0,0 +1,116 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Gdata_Entry
+ */
+require_once 'Zend/Gdata/Entry.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ */
+class Zend_Gdata_Analytics_DataEntry extends Zend_Gdata_Entry
+{
+	/**
+	 * @var array
+	 */
+	protected $_dimensions = array();
+	/**
+	 * @var array
+	 */
+	protected $_metrics = array();
+
+	/**
+	 * @param DOMElement $element
+	 */
+    public function __construct($element = null)
+    {
+        $this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces);
+        parent::__construct($element);
+    }
+
+	/**
+     * @param DOMElement $child
+     * @return void
+     */
+    protected function takeChildFromDOM($child)
+    {
+        $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
+        switch ($absoluteNodeName) {
+        	case $this->lookupNamespace('ga') . ':' . 'dimension';
+	            $dimension = new Zend_Gdata_Analytics_Extension_Dimension();
+	            $dimension->transferFromDOM($child);
+	            $this->_dimensions[] = $dimension;
+                break;
+        	case $this->lookupNamespace('ga') . ':' . 'metric';
+	            $metric = new Zend_Gdata_Analytics_Extension_Metric();
+	            $metric->transferFromDOM($child);
+	            $this->_metrics[] = $metric;
+                break;
+        	default:
+            	parent::takeChildFromDOM($child);
+                break;
+        }
+    }
+
+	/**
+	 * @param string $name 
+	 * @return mixed
+	 */
+	public function getDimension($name)
+	{
+		foreach ($this->_dimensions as $dimension) {
+			if ($dimension->getName() == $name) {
+				return $dimension;
+			}
+		}
+		return null;
+	}
+	
+	/** 
+	 * @param string $name 
+	 * @return mixed
+	 */
+	public function getMetric($name)
+	{
+		foreach ($this->_metrics as $metric) {
+			if ($metric->getName() == $name) {
+				return $metric;
+			}
+		}
+		return null;
+	}
+	
+	/**
+	 * @param string $name 
+	 * @return mixed
+	 */
+	public function getValue($name)
+	{
+		if (null !== ($metric = $this->getMetric($name))) {
+			return $metric;
+		}
+		return $this->getDimension($name);
+	}
+}

+ 64 - 0
library/Zend/Gdata/Analytics/DataFeed.php

@@ -0,0 +1,64 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Gdata_Feed
+ */
+require_once 'Zend/Gdata/Feed.php';
+
+/**
+ * @see Zend_Gdata_Analytics
+ */
+require_once 'Zend/Gdata/Analytics.php';
+
+/**
+ * @see Zend_Gdata_Geo_Entry
+ */
+require_once 'Zend/Gdata/Analytics/DataEntry.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ */
+class Zend_Gdata_Analytics_DataFeed extends Zend_Gdata_Feed
+{
+
+    /**
+     * The classname for individual feed elements.
+     *
+     * @var string
+     */
+    protected $_entryClassName = 'Zend_Gdata_Analytics_DataEntry';
+    /**
+     * The classname for the feed.
+     *
+     * @var string
+     */
+    protected $_feedClassName = 'Zend_Gdata_Analytics_DataFeed';
+
+    public function __construct($element = null)
+    {
+        $this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces);
+        parent::__construct($element);
+    }
+}

+ 423 - 0
library/Zend/Gdata/Analytics/DataQuery.php

@@ -0,0 +1,423 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Gdata_Query
+ */
+require_once 'Zend/Gdata/Query.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ */
+class Zend_Gdata_Analytics_DataQuery extends Zend_Gdata_Query
+{
+    const ANALYTICS_FEED_URI = 'http://www.google.com/analytics/feeds/data';
+
+    /**
+     * The default URI used for feeds.
+     */
+    protected $_defaultFeedUri = self::ANALYTICS_FEED_URI;
+
+    // D1. Visitor
+    const DIMENSION_BROWSER = 'ga:browser';
+    const DIMENSION_BROWSER_VERSION = 'ga:browserVersion';
+    const DIMENSION_CITY = 'ga:city';
+    const DIMENSION_CONNECTIONSPEED = 'ga:connectionSpeed';
+    const DIMENSION_CONTINENT = 'ga:continent';
+    const DIMENSION_COUNTRY = 'ga:country';
+    const DIMENSION_DATE = 'ga:date';
+    const DIMENSION_DAY = 'ga:day';
+    const DIMENSION_DAYS_SINCE_LAST_VISIT= 'ga:daysSinceLastVisit';
+    const DIMENSION_FLASH_VERSION = 'ga:flashVersion';
+    const DIMENSION_HOSTNAME = 'ga:hostname';
+    const DIMENSION_HOUR = 'ga:hour';
+    const DIMENSION_JAVA_ENABLED= 'ga:javaEnabled';
+    const DIMENSION_LANGUAGE= 'ga:language';
+    const DIMENSION_LATITUDE = 'ga:latitude';
+    const DIMENSION_LONGITUDE = 'ga:longitude';
+    const DIMENSION_MONTH = 'ga:month';
+    const DIMENSION_NETWORK_DOMAIN = 'ga:networkDomain';
+    const DIMENSION_NETWORK_LOCATION = 'ga:networkLocation';
+    const DIMENSION_OPERATING_SYSTEM = 'ga:operatingSystem';
+    const DIMENSION_OPERATING_SYSTEM_VERSION = 'ga:operatingSystemVersion';
+    const DIMENSION_PAGE_DEPTH = 'ga:pageDepth';
+    const DIMENSION_REGION = 'ga:region';
+    const DIMENSION_SCREEN_COLORS= 'ga:screenColors';
+    const DIMENSION_SCREEN_RESOLUTION = 'ga:screenResolution';
+    const DIMENSION_SUB_CONTINENT = 'ga:subContinent';
+    const DIMENSION_USER_DEFINED_VALUE = 'ga:userDefinedValue';
+    const DIMENSION_VISIT_COUNT = 'ga:visitCount';
+    const DIMENSION_VISIT_LENGTH = 'ga:visitLength';
+    const DIMENSION_VISITOR_TYPE = 'ga:visitorType';
+    const DIMENSION_WEEK = 'ga:week';
+    const DIMENSION_YEAR = 'ga:year';
+
+    // D2. Campaign
+    const DIMENSION_AD_CONTENT = 'ga:adContent';
+    const DIMENSION_AD_GROUP = 'ga:adGroup';
+    const DIMENSION_AD_SLOT = 'ga:adSlot';
+    const DIMENSION_AD_SLOT_POSITION = 'ga:adSlotPosition';
+    const DIMENSION_CAMPAIGN = 'ga:campaign';
+    const DIMENSION_KEYWORD = 'ga:keyword';
+    const DIMENSION_MEDIUM = 'ga:medium';
+    const DIMENSION_REFERRAL_PATH = 'ga:referralPath';
+    const DIMENSION_SOURCE = 'ga:source';
+
+    // D3. Content
+    const DIMENSION_EXIT_PAGE_PATH = 'ga:exitPagePath';
+    const DIMENSION_LANDING_PAGE_PATH = 'ga:landingPagePath';
+    const DIMENSION_PAGE_PATH = 'ga:pagePath';
+    const DIMENSION_PAGE_TITLE = 'ga:pageTitle';
+    const DIMENSION_SECOND_PAGE_PATH = 'ga:secondPagePath';
+
+    // D4. Ecommerce
+    const DIMENSION_AFFILIATION = 'ga:affiliation';
+    const DIMENSION_DAYS_TO_TRANSACTION = 'ga:daysToTransaction';
+    const DIMENSION_PRODUCT_CATEGORY = 'ga:productCategory';
+    const DIMENSION_PRODUCT_NAME = 'ga:productName';
+    const DIMENSION_PRODUCT_SKU = 'ga:productSku';
+    const DIMENSION_TRANSACTION_ID = 'ga:transactionId';
+    const DIMENSION_VISITS_TO_TRANSACTION = 'ga:visitsToTransaction';
+
+    // D5. Internal Search
+    const DIMENSION_SEARCH_CATEGORY = 'ga:searchCategory';
+    const DIMENSION_SEARCH_DESTINATION_PAGE = 'ga:searchDestinationPage';
+    const DIMENSION_SEARCH_KEYWORD = 'ga:searchKeyword';
+    const DIMENSION_SEARCH_KEYWORD_REFINEMENT = 'ga:searchKeywordRefinement';
+    const DIMENSION_SEARCH_START_PAGE = 'ga:searchStartPage';
+    const DIMENSION_SEARCH_USED = 'ga:searchUsed';
+
+    // D6. Navigation
+    const DIMENSION_NEXT_PAGE_PATH = 'ga:nextPagePath';
+    const DIMENSION_PREV_PAGE_PATH= 'ga:previousPagePath';
+
+    // D7. Events
+    const DIMENSION_EVENT_CATEGORY = 'ga:eventCategory';
+    const DIMENSION_EVENT_ACTION = 'ga:eventAction';
+    const DIMENSION_EVENT_LABEL = 'ga:eventLabel';
+
+    // D8. Custon Variables
+    const DIMENSION_CUSTOM_VAR_NAME_1 = 'ga:customVarName1';
+    const DIMENSION_CUSTOM_VAR_NAME_2 = 'ga:customVarName2';
+    const DIMENSION_CUSTOM_VAR_NAME_3 = 'ga:customVarName3';
+    const DIMENSION_CUSTOM_VAR_NAME_4 = 'ga:customVarName4';
+    const DIMENSION_CUSTOM_VAR_NAME_5 = 'ga:customVarName5';
+    const DIMENSION_CUSTOM_VAR_VALUE_1 = 'ga:customVarValue1';
+    const DIMENSION_CUSTOM_VAR_VALUE_2 = 'ga:customVarValue2';
+    const DIMENSION_CUSTOM_VAR_VALUE_3 = 'ga:customVarValue3';
+    const DIMENSION_CUSTOM_VAR_VALUE_4 = 'ga:customVarValue4';
+    const DIMENSION_CUSTOM_VAR_VALUE_5 = 'ga:customVarValue5';
+
+    // M1. Visitor
+    const METRIC_BOUNCES = 'ga:bounces';
+    const METRIC_ENTRANCES = 'ga:entrances';
+    const METRIC_EXITS = 'ga:exits';
+    const METRIC_NEW_VISITS = 'ga:newVisits';
+    const METRIC_PAGEVIEWS = 'ga:pageviews';
+    const METRIC_TIME_ON_PAGE = 'ga:timeOnPage';
+    const METRIC_TIME_ON_SITE = 'ga:timeOnSite';
+    const METRIC_VISITORS = 'ga:visitors';
+    const METRIC_VISITS = 'ga:visits';
+
+    // M2. Campaign
+    const METRIC_AD_CLICKS = 'ga:adClicks';
+    const METRIC_AD_COST = 'ga:adCost';
+    const METRIC_CPC = 'ga:CPC';
+    const METRIC_CPM = 'ga:CPM';
+    const METRIC_CTR = 'ga:CTR';
+    const METRIC_IMPRESSIONS = 'ga:impressions';
+
+    // M3. Content
+    const METRIC_UNIQUE_PAGEVIEWS = 'ga:uniquePageviews';
+
+    // M4. Ecommerce
+    const METRIC_ITEM_REVENUE = 'ga:itemRevenue';
+    const METRIC_ITEM_QUANTITY = 'ga:itemQuantity';
+    const METRIC_TRANSACTIONS = 'ga:transactions';
+    const METRIC_TRANSACTION_REVENUE = 'ga:transactionRevenue';
+    const METRIC_TRANSACTION_SHIPPING = 'ga:transactionShipping';
+    const METRIC_TRANSACTION_TAX = 'ga:transactionTax';
+    const METRIC_UNIQUE_PURCHASES = 'ga:uniquePurchases';
+
+    // M5. Internal Search
+    const METRIC_SEARCH_DEPTH = 'ga:searchDepth';
+    const METRIC_SEARCH_DURATION = 'ga:searchDuration';
+    const METRIC_SEARCH_EXITS = 'ga:searchExits';
+    const METRIC_SEARCH_REFINEMENTS = 'ga:searchRefinements';
+    const METRIC_SEARCH_UNIQUES = 'ga:searchUniques';
+    const METRIC_SEARCH_VISIT = 'ga:searchVisits';
+
+    // M6. Goals
+    const METRIC_GOAL_COMPLETIONS_ALL = 'ga:goalCompletionsAll';
+    const METRIC_GOAL_STARTS_ALL = 'ga:goalStartsAll';
+    const METRIC_GOAL_VALUE_ALL = 'ga:goalValueAll';
+    // TODO goals 1-20
+    const METRIC_GOAL_1_COMPLETION = 'ga:goal1Completions';
+    const METRIC_GOAL_1_STARTS = 'ga:goal1Starts';
+    const METRIC_GOAL_1_VALUE = 'ga:goal1Value';
+
+    // M7. Events
+    const METRIC_TOTAL_EVENTS = 'ga:totalEvents';
+    const METRIC_UNIQUE_EVENTS = 'ga:uniqueEvents';
+    const METRIC_EVENT_VALUE = 'ga:eventValue';
+    
+    // suported filter operators
+    const EQUALS = "==";
+    const EQUALS_NOT = "!=";
+    const GREATER = ">";
+    const LESS = ">";
+    const GREATER_EQUAL = ">=";
+    const LESS_EQUAL = "<=";
+    const CONTAINS = "=@";
+    const CONTAINS_NOT ="!@";
+    const REGULAR ="=~";
+    const REGULAR_NOT ="!~";
+    
+    /**
+     * @var string
+     */
+    protected $_profileId;
+    /**
+     * @var array
+     */
+    protected $_dimensions = array();
+    /**
+     * @var array
+     */
+    protected $_metrics = array();
+    /**
+     * @var array
+     */
+    protected $_sort = array();
+    /**
+     * @var array
+     */
+    protected $_filters = array();
+    
+    /**
+     * @param string $id
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function setProfileId($id)
+    {
+        $this->_profileId = $id;
+        return $this;
+    }
+
+    /**
+     * @return string
+     */
+    public function getProfileId()
+    {
+        return $this->_profileId;
+    }
+
+    /**
+     * @param string $dimension
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function addDimension($dimension)
+    {
+        $this->_dimensions[$dimension] = true;        
+        return $this;
+    }
+
+    /**
+     * @param string $metric
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function addMetric($metric)
+    {
+        $this->_metrics[$metric] = true;
+        return $this;
+    }
+
+    /**
+     * @return array
+     */
+    public function getDimensions()
+    {
+        return $this->_dimensions;
+    }
+
+    /**
+     * @return array
+     */
+    public function getMetrics()
+    {
+        return $this->_metrics;
+    }
+
+    /**
+     * @param string $dimension
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function removeDimension($dimension)
+    {
+        unset($this->_dimensions[$dimension]);
+        return $this;
+    }
+    /**
+     * @param string $metric
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function removeMetric($metric)
+    {
+        unset($this->_metrics[$metric]);
+        return $this;
+    }
+    /**
+     * @param string $value
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function setStartDate($date)
+    {
+        $this->setParam("start-date", $date);
+        return $this;
+    }
+    /**
+     * @param string $value
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function setEndDate($date)
+    {
+        $this->setParam("end-date", $date);
+        return $this;
+    }
+    
+    /**
+     * @param string $filter
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function addFilter($filter)
+    {
+        $this->_filters[] = array($filter, true);
+        return $this;
+    }
+    
+    /**
+     * @param string $filter
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function addOrFilter($filter)
+    {
+        $this->_filters[] = array($filter, false);
+        return $this;
+    }
+    
+    /**
+     * @deprecated
+     * @param string $value
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function setFilter($value)
+    {
+        return $this->addFilter($value);
+    }
+    /**
+     * @param string $sort
+     * @param boolean[optional] $descending
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function addSort($sort, $descending=false)
+    {
+        // add to sort storage
+        $this->_sort[] = ($descending?'-':'').$sort;
+        return $this;
+    }
+    
+    /**
+     * @deprecated
+     * @param string $sort
+     * @param boolean[optional] $descending
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function setSort($sort, $descending=false)
+    {
+        return $this->addSort($sort, $descending);
+    }
+    
+    /**
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function clearSort()
+    {
+        $this->_sort = array();
+        return $this;
+    }
+    
+    /**
+     * @param string $segment
+     * @return Zend_Gdata_Analytics_DataQuery
+     */
+    public function setSegment($segment)
+    {
+        $this->setParam('segment', $segment);
+        return $this;
+    }
+
+    /**
+     * @return string url
+     */
+    public function getQueryUrl()
+    {
+        $uri = $this->_defaultFeedUri;
+        if (isset($this->_url)) {
+            $uri = $this->_url;
+        }
+        
+        $dimensions = $this->getDimensions();
+        if (!empty($dimensions)) {
+            $this->setParam('dimensions', implode(",", array_keys($dimensions)));
+        }
+        
+        $metrics = $this->getMetrics();
+        if (!empty($metrics)) {
+            $this->setParam('metrics', implode(",", array_keys($metrics)));
+        }
+        
+        // profile id (ga:tableId)
+        if ($this->getProfileId() != null) {
+            $this->setParam('ids', 'ga:'.ltrim($this->getProfileId(), "ga:"));
+        }
+                
+        // sorting
+        if ($this->_sort) {
+            $this->setParam('sort', implode(",", $this->_sort));
+        }
+        
+        // filtering
+        $filters = "";
+        foreach ($this->_filters as $filter) {
+            $filters.=($filter[1]===true?';':',').$filter[0];
+        }
+        
+        if ($filters!="") {
+            $this->setParam('filters', ltrim($filters, ",;"));
+        }
+        
+        $uri .= $this->getQueryString();
+        return $uri;
+    }
+}

+ 40 - 0
library/Zend/Gdata/Analytics/Extension/Dimension.php

@@ -0,0 +1,40 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Gdata_Extension_Metric
+ */
+require_once 'Zend/Gdata/Analytics/Extension/Metric.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ */
+class Zend_Gdata_Analytics_Extension_Dimension 
+    extends Zend_Gdata_Analytics_Extension_Metric
+{
+    protected $_rootNamespace = 'ga';
+    protected $_rootElement = 'dimension';
+    protected $_value = null;
+    protected $_name = null;
+}

+ 54 - 0
library/Zend/Gdata/Analytics/Extension/Metric.php

@@ -0,0 +1,54 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Gdata_Extension_Property
+ */
+require_once 'Zend/Gdata/Analytics/Extension/Property.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ */
+class Zend_Gdata_Analytics_Extension_Metric 
+    extends Zend_Gdata_Analytics_Extension_Property
+{
+    protected $_rootNamespace = 'ga';
+    protected $_rootElement = 'metric';
+    protected $_value = null;
+    protected $_name = null;
+
+	protected function takeAttributeFromDOM($attribute)
+    {
+        switch ($attribute->localName) {
+	        case 'name':
+	        	$this->_name = $attribute->nodeValue;
+		        break;
+	        case 'value':
+	            $this->_value = $attribute->nodeValue;
+	            break;
+	        default:
+	            parent::takeAttributeFromDOM($attribute);
+        }
+    }
+}

+ 121 - 0
library/Zend/Gdata/Analytics/Extension/Property.php

@@ -0,0 +1,121 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Gdata_Extension
+ */
+require_once 'Zend/Gdata/Extension.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ */
+class Zend_Gdata_Analytics_Extension_Property extends Zend_Gdata_Extension
+{
+    protected $_rootNamespace = 'ga';
+    protected $_rootElement = 'property';
+    protected $_value = null;
+    protected $_name = null;
+
+    /**
+     * Constructs a new Zend_Gdata_Calendar_Extension_Timezone object.
+     * @param string $value (optional) The text content of the element.
+     */
+    public function __construct($value = null, $name = null)
+    {
+        $this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces);
+        parent::__construct();
+        $this->_value = $value;
+        $this->_name = $name;
+    }
+
+    /**
+     * Given a DOMNode representing an attribute, tries to map the data into
+     * instance members.  If no mapping is defined, the name and value are
+     * stored in an array.
+     *
+     * @param DOMNode $attribute The DOMNode attribute needed to be handled
+     */
+    protected function takeAttributeFromDOM($attribute)
+    {
+        switch ($attribute->localName) {
+            case 'name':
+            	$this->_name = substr($attribute->nodeValue, 3);
+    	        break;
+            case 'value':
+                $this->_value = $attribute->nodeValue;
+                break;
+            default:
+                parent::takeAttributeFromDOM($attribute);
+        }
+    }
+
+    /**
+     * Get the value for this element's value attribute.
+     *
+     * @return string The value associated with this attribute.
+     */
+    public function getValue()
+    {
+        return $this->_value;
+    }
+
+    /**
+     * Set the value for this element's value attribute.
+     *
+     * @param string $value The desired value for this attribute.
+     * @return Zend_Gdata_Analytics_Extension_Property The element being modified.
+     */
+    public function setValue($value)
+    {
+        $this->_value = $value;
+        return $this;
+    }
+
+    /**
+     * @param string $name
+     * @return Zend_Gdata_Analytics_Extension_Property
+     */
+    public function setName($name)
+    {
+    	$this->_name = $name;
+    	return $this;
+    }
+
+    /**
+     * @return string
+     */
+    public function getName()
+    {
+    	return $this->_name;
+    }
+
+    /**
+     * Magic toString method allows using this directly via echo
+     * Works best in PHP >= 4.2.0
+     */
+    public function __toString()
+    {
+        return $this->getValue();
+    }
+}

+ 112 - 0
library/Zend/Gdata/Analytics/Extension/TableId.php

@@ -0,0 +1,112 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Gdata_Extension
+ */
+require_once 'Zend/Gdata/Extension.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata
+ * @subpackage Analytics
+ */
+class Zend_Gdata_Analytics_Extension_TableId extends Zend_Gdata_Extension
+{
+
+    protected $_rootNamespace = 'ga';
+    protected $_rootElement = 'tableId';
+    protected $_value = null;
+
+    /**
+     * Constructs a new Zend_Gdata_Calendar_Extension_Timezone object.
+     * @param string $value (optional) The text content of the element.
+     */
+    public function __construct($value = null)
+    {
+        $this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces);
+        parent::__construct();
+        $this->_value = $value;
+    }
+
+    /**
+     * Retrieves a DOMElement which corresponds to this element and all
+     * child properties.  This is used to build an entry back into a DOM
+     * and eventually XML text for sending to the server upon updates, or
+     * for application storage/persistence.
+     *
+     * @param DOMDocument $doc The DOMDocument used to construct DOMElements
+     * @return DOMElement The DOMElement representing this element and all
+     * child properties.
+     */
+    public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
+    {
+        $element = parent::getDOM($doc, $majorVersion, $minorVersion);
+        if ($this->_value != null) {
+            $element->setAttribute('value', $this->_value);
+        }
+        return $element;
+    }
+
+    /**
+     * Given a DOMNode representing an attribute, tries to map the data into
+     * instance members.  If no mapping is defined, the name and value are
+     * stored in an array.
+     *
+     * @param DOMNode $attribute The DOMNode attribute needed to be handled
+     */
+    protected function takeChildFromDOM($child)
+    {
+       $this->_value = $child->nodeValue;
+    }
+
+    /**
+     * Get the value for this element's value attribute.
+     *
+     * @return string The value associated with this attribute.
+     */
+    public function getValue()
+    {
+        return $this->_value;
+    }
+
+    /**
+     * Set the value for this element's value attribute.
+     *
+     * @param string $value The desired value for this attribute.
+     * @return Zend_Gdata_Calendar_Extension_Timezone The element being modified.
+     */
+    public function setValue($value)
+    {
+        $this->_value = $value;
+        return $this;
+    }
+
+    /**
+     * Magic toString method allows using this directly via echo
+     * Works best in PHP >= 4.2.0
+     */
+    public function __toString()
+    {
+        return $this->getValue();
+    }
+}

+ 5 - 0
tests/Zend/Gdata/AllTests.php

@@ -30,6 +30,11 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
 require_once 'Zend/Gdata/AuthSubTest.php';
 
 /**
+ * 
+ */
+require_once 'Zend/Gdata/Analytics/AccountFeedTest.php';
+
+/**
  * Tests that do not require online access to servers
  */
 require_once 'Zend/Gdata/AppTest.php';

+ 54 - 0
tests/Zend/Gdata/Analytics/AccountFeedTest.php

@@ -0,0 +1,54 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata_Analytics
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once 'Zend/Gdata/Analytics.php';
+require_once 'Zend/Http/Client.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata_Analytics
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @group      Zend_Gdata
+ * @group      Zend_Gdata_Analytics
+ */
+class Zend_Gdata_Analytics_AccountFeedTest extends PHPUnit_Framework_TestCase
+{
+
+    public function setUp()
+    {
+        $this->accountFeed = new Zend_Gdata_Analytics_AccountFeed(
+            file_get_contents(dirname(__FILE__) . '/_files/TestAccountFeed.xml'),
+            true
+        );
+    }
+
+    public function testAccountFeed()
+    {
+        $this->assertEquals(count($this->accountFeed->entries), 3);
+        $this->assertEquals($this->accountFeed->entries->count(), 3);
+        foreach ($this->accountFeed->entries as $entry) {
+            $this->assertTrue($entry instanceof Zend_Gdata_Analytics_AccountEntry);
+        }
+    }
+}

+ 80 - 0
tests/Zend/Gdata/Analytics/DataFeedTest.php

@@ -0,0 +1,80 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Gdata_Analytics
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once 'Zend/Gdata/Analytics.php';
+require_once 'Zend/Http/Client.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Gdata_Analytics
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @group      Zend_Gdata
+ * @group      Zend_Gdata_Analytics
+ */
+class Zend_Gdata_Analytics_DataFeedTest extends PHPUnit_Framework_TestCase
+{
+    public $testData = array(
+        'blogger.com' => 68140,
+        'google.com'  => 29666,
+        'stumbleupon.com' => 4012, 
+        'google.co.uk' => 2968, 
+        'google.co.in' => 2793,        
+    );
+    
+    public function setUp()
+    {
+        $this->dataFeed = new Zend_Gdata_Analytics_DataFeed(
+            file_get_contents(dirname(__FILE__) . '/_files/TestDataFeed.xml'),
+            true
+        );
+    }
+
+    public function testDataFeed()
+    {
+        $count = count($this->testData);
+        $this->assertEquals(count($this->dataFeed->entries), $count);
+        $this->assertEquals($this->dataFeed->entries->count(), $count);
+        foreach ($this->dataFeed->entries as $entry) {
+            $this->assertTrue($entry instanceof Zend_Gdata_Analytics_DataEntry);
+        }
+    }
+    
+    public function testGetters()
+    {
+        $sources = array_keys($this->testData);
+        $values = array_values($this->testData);
+        
+        foreach ($this->dataFeed as $index => $row) {
+            $source = $row->getDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_SOURCE);
+            $medium = $row->getDimension('ga:medium');
+            $visits = $row->getMetric('ga:visits');
+            $visitsValue = $row->getValue('ga:visits');
+            
+            $this->assertEquals("$medium", 'referral');
+            $this->assertEquals("$source", $sources[$index]);
+            $this->assertEquals("$visits", $values[$index]);
+            $this->assertEquals("$visitsValue", $values[$index]);
+        }
+    }
+}

+ 110 - 0
tests/Zend/Gdata/Analytics/_files/TestAccountFeed.xml

@@ -0,0 +1,110 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<feed xmlns='http://www.w3.org/2005/Atom' xmlns:dxp='http://schemas.google.com/analytics/2009' xmlns:ga='http://schemas.google.com/ga/2009' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;DUcCRX47eCp7I2A9WxNbFkk.&quot;' gd:kind='analytics#accounts'>
+        <id>http://www.google.com/analytics/feeds/accounts/abc@test.com</id>
+        <updated>2009-11-19T08:11:04.000-08:00</updated>
+        <title>Profile list for abc@test.com</title>
+        <link rel='self' type='application/atom+xml' href='http://www.google.com/analytics/feeds/accounts/default'/>
+        <author>
+                <name>Google Analytics</name>
+        </author>
+        <generator version='1.0'>Google Analytics</generator>
+        <openSearch:totalResults>41</openSearch:totalResults>
+        <openSearch:startIndex>1</openSearch:startIndex>
+        <openSearch:itemsPerPage>3</openSearch:itemsPerPage>
+        <dxp:segment id='gaid::-1' name='All Visits'>
+                <dxp:definition> </dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-2' name='New Visitors'>
+                <dxp:definition>ga:visitorType==New Visitor</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-3' name='Returning Visitors'>
+                <dxp:definition>ga:visitorType==Returning Visitor</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-4' name='Paid Search Traffic'>
+                <dxp:definition>ga:medium==cpa,ga:medium==cpc,ga:medium==cpm,ga:medium==cpp,ga:medium==cpv,ga:medium==ppc</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-5' name='Non-paid Search Traffic'>
+                <dxp:definition>ga:medium==organic</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-6' name='Search Traffic'>
+                <dxp:definition>ga:medium==cpa,ga:medium==cpc,ga:medium==cpm,ga:medium==cpp,ga:medium==cpv,ga:medium==organic,ga:medium==ppc</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-7' name='Direct Traffic'>
+                <dxp:definition>ga:medium==(none)</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-8' name='Referral Traffic'>
+                <dxp:definition>ga:medium==referral</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-9' name='Visits with Conversions'>
+                <dxp:definition>ga:goalCompletionsAll&gt;0</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-10' name='Visits with Transactions'>
+                <dxp:definition>ga:transactions&gt;0</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-11' name='Visits from iPhones'>
+                <dxp:definition>ga:operatingSystem==iPhone</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::-12' name='Non-bounce Visits'>
+                <dxp:definition>ga:bounces==0</dxp:definition>
+        </dxp:segment>
+        <dxp:segment id='gaid::0' name='Sources Form Google'>
+                <dxp:definition>ga:source=~^\Qgoogle\E</dxp:definition>
+        </dxp:segment>
+        <entry gd:etag='W/&quot;DUcCRX47eCp7I2A9WxNbFkk.&quot;' gd:kind='analytics#account'>
+                <id>http://www.google.com/analytics/feeds/accounts/ga:1174</id>
+                <updated>2009-11-19T08:11:04.000-08:00</updated>
+                <title>www.googlestore.com</title>
+                <link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
+                <ga:goal active='true' name='Completing Order' number='1' value='10.0'>
+                        <ga:destination caseSensitive='false' expression='/purchaseComplete.html' matchType='regex' step1Required='false'>
+                                <ga:step name='View Product Categories' number='1' path='/Apps|Accessories'/>
+                                <ga:step name='View Product' number='2' path='/Apps|Accessories/(.*)\.axd'/>
+                                <ga:step name='View Shopping Cart' number='3' path='/shoppingcart.aspx'/>
+                                <ga:step name='Login' number='4' path='/login.html'/>
+                                <ga:step name='Place Order' number='5' path='/placeOrder.html'/>
+                        </ga:destination>
+                </ga:goal>
+                <ga:goal active='true' name='Browsed my site over 5 minutes' number='2' value='0.0'>
+                        <ga:engagement comparison='&gt;' thresholdValue='300' type='timeOnSite'/>
+                </ga:goal>
+                <ga:goal active='true' name='Visited &gt; 4 pages' number='3' value='0.25'>
+                        <ga:engagement comparison='&gt;' thresholdValue='4' type='pagesVisited'/>
+                </ga:goal>
+                <dxp:property name='ga:accountId' value='30481'/>
+                <dxp:property name='ga:accountName' value='Google Store'/>
+                <dxp:property name='ga:profileId' value='1174'/>
+                <dxp:property name='ga:webPropertyId' value='UA-30481-1'/>
+                <dxp:property name='ga:currency' value='USD'/>
+                <dxp:property name='ga:timezone' value='America/Los_Angeles'/>
+                <dxp:tableId>ga:1174</dxp:tableId>
+        </entry>
+        <entry gd:etag='W/&quot;DkEASH47eCp7I2A9WxNbFUo.&quot;' gd:kind='analytics#account'>
+                <id>http://www.google.com/analytics/feeds/accounts/ga:11380020</id>
+                <updated>2009-11-18T12:04:09.000-08:00</updated>
+                <title>Googlestore - overall</title>
+                <link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
+                <ga:goal active='false' name='goal2.html' number='1' value='0.0'>
+                        <ga:destination caseSensitive='false' expression='/goal2.html' matchType='head' step1Required='false'/>
+                </ga:goal>
+                <dxp:property name='ga:accountId' value='30481'/>
+                <dxp:property name='ga:accountName' value='Google Store'/>
+                <dxp:property name='ga:profileId' value='11380020'/>
+                <dxp:property name='ga:webPropertyId' value='UA-30481-1'/>
+                <dxp:property name='ga:currency' value='USD'/>
+                <dxp:property name='ga:timezone' value='America/Los_Angeles'/>
+                <dxp:tableId>ga:11380020</dxp:tableId>
+        </entry>
+        <entry gd:etag='W/&quot;C04HRn47eCp7I2A9WxJbGUQ.&quot;' gd:kind='analytics#account'>
+                <id>http://www.google.com/analytics/feeds/accounts/ga:11380025</id>
+                <updated>2009-07-30T15:12:17.000-07:00</updated>
+                <title>Googlestore - no filters</title>
+                <link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
+                <dxp:property name='ga:accountId' value='30481'/>
+                <dxp:property name='ga:accountName' value='Google Store'/>
+                <dxp:property name='ga:profileId' value='11380025'/>
+                <dxp:property name='ga:webPropertyId' value='UA-30481-1'/>
+                <dxp:property name='ga:currency' value='USD'/>
+                <dxp:property name='ga:timezone' value='America/Los_Angeles'/>
+                <dxp:tableId>ga:11380025</dxp:tableId>
+        </entry>
+</feed>

+ 79 - 0
tests/Zend/Gdata/Analytics/_files/TestDataFeed.xml

@@ -0,0 +1,79 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<feed xmlns='http://www.w3.org/2005/Atom' xmlns:dxp='http://schemas.google.com/analytics/2009' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;DUINSHcycSp7I2A9WxRWFEQ.&quot;' gd:kind='analytics#data'>
+        <id>http://www.google.com/analytics/feeds/data?ids=ga:1174&amp;dimensions=ga:medium,ga:source&amp;metrics=ga:bounces,ga:visits&amp;filters=ga:medium%3D%3Dreferral&amp;start-date=2008-10-01&amp;end-date=2008-10-31</id>
+        <updated>2008-10-31T16:59:59.999-07:00</updated>
+        <title>Google Analytics Data for Profile 1174</title>
+        <link rel='self' type='application/atom+xml' href='http://www.google.com/analytics/feeds/data?max-results=5&amp;sort=-ga%3Avisits&amp;end-date=2008-10-31&amp;start-date=2008-10-01&amp;metrics=ga%3Avisits%2Cga%3Abounces&amp;ids=ga%3A1174&amp;dimensions=ga%3Asource%2Cga%3Amedium&amp;filters=ga%3Amedium%3D%3Dreferral'/>
+        <link rel='next' type='application/atom+xml' href='http://www.google.com/analytics/feeds/data?start-index=6&amp;max-results=5&amp;sort=-ga%3Avisits&amp;end-date=2008-10-31&amp;start-date=2008-10-01&amp;metrics=ga%3Avisits%2Cga%3Abounces&amp;ids=ga%3A1174&amp;dimensions=ga%3Asource%2Cga%3Amedium&amp;filters=ga%3Amedium%3D%3Dreferral'/>
+        <author>
+                <name>Google Analytics</name>
+        </author>
+        <generator version='1.0'>Google Analytics</generator>
+        <openSearch:totalResults>6451</openSearch:totalResults>
+        <openSearch:startIndex>1</openSearch:startIndex>
+        <openSearch:itemsPerPage>5</openSearch:itemsPerPage>
+        <dxp:aggregates>
+                <dxp:metric confidenceInterval='0.0' name='ga:visits' type='integer' value='136540'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:bounces' type='integer' value='101535'/>
+        </dxp:aggregates>
+        <dxp:containsSampledData>false</dxp:containsSampledData>
+        <dxp:dataSource>
+                <dxp:property name='ga:profileId' value='1174'/>
+                <dxp:property name='ga:webPropertyId' value='UA-30481-1'/>
+                <dxp:property name='ga:accountName' value='Google Store'/>
+                <dxp:tableId>ga:1174</dxp:tableId>
+                <dxp:tableName>www.googlestore.com</dxp:tableName>
+        </dxp:dataSource>
+        <dxp:endDate>2008-10-31</dxp:endDate>
+        <dxp:startDate>2008-10-01</dxp:startDate>
+        <entry gd:etag='W/&quot;C0UEQX47eSp7I2A9WxRWFEw.&quot;' gd:kind='analytics#datarow'>
+                <id>http://www.google.com/analytics/feeds/data?ids=ga:1174&amp;ga:medium=referral&amp;ga:source=blogger.com&amp;filters=ga:medium%3D%3Dreferral&amp;start-date=2008-10-01&amp;end-date=2008-10-31</id>
+                <updated>2008-10-30T17:00:00.001-07:00</updated>
+                <title>ga:source=blogger.com | ga:medium=referral</title>
+                <link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
+                <dxp:dimension name='ga:source' value='blogger.com'/>
+                <dxp:dimension name='ga:medium' value='referral'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:visits' type='integer' value='68140'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:bounces' type='integer' value='61095'/>
+        </entry>
+        <entry gd:etag='W/&quot;C0UEQX47eSp7I2A9WxRWFEw.&quot;' gd:kind='analytics#datarow'>
+                <id>http://www.google.com/analytics/feeds/data?ids=ga:1174&amp;ga:medium=referral&amp;ga:source=google.com&amp;filters=ga:medium%3D%3Dreferral&amp;start-date=2008-10-01&amp;end-date=2008-10-31</id>
+                <updated>2008-10-30T17:00:00.001-07:00</updated>
+                <title>ga:source=google.com | ga:medium=referral</title>
+                <link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
+                <dxp:dimension name='ga:source' value='google.com'/>
+                <dxp:dimension name='ga:medium' value='referral'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:visits' type='integer' value='29666'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:bounces' type='integer' value='14979'/>
+        </entry>
+        <entry gd:etag='W/&quot;C0UEQX47eSp7I2A9WxRWFEw.&quot;' gd:kind='analytics#datarow'>
+                <id>http://www.google.com/analytics/feeds/data?ids=ga:1174&amp;ga:medium=referral&amp;ga:source=stumbleupon.com&amp;filters=ga:medium%3D%3Dreferral&amp;start-date=2008-10-01&amp;end-date=2008-10-31</id>
+                <updated>2008-10-30T17:00:00.001-07:00</updated>
+                <title>ga:source=stumbleupon.com | ga:medium=referral</title>
+                <link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
+                <dxp:dimension name='ga:source' value='stumbleupon.com'/>
+                <dxp:dimension name='ga:medium' value='referral'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:visits' type='integer' value='4012'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:bounces' type='integer' value='848'/>
+        </entry>
+        <entry gd:etag='W/&quot;C0UEQX47eSp7I2A9WxRWFEw.&quot;' gd:kind='analytics#datarow'>
+                <id>http://www.google.com/analytics/feeds/data?ids=ga:1174&amp;ga:medium=referral&amp;ga:source=google.co.uk&amp;filters=ga:medium%3D%3Dreferral&amp;start-date=2008-10-01&amp;end-date=2008-10-31</id>
+                <updated>2008-10-30T17:00:00.001-07:00</updated>
+                <title>ga:source=google.co.uk | ga:medium=referral</title>
+                <link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
+                <dxp:dimension name='ga:source' value='google.co.uk'/>
+                <dxp:dimension name='ga:medium' value='referral'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:visits' type='integer' value='2968'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:bounces' type='integer' value='2084'/>
+        </entry>
+        <entry gd:etag='W/&quot;C0UEQX47eSp7I2A9WxRWFEw.&quot;' gd:kind='analytics#datarow'>
+                <id>http://www.google.com/analytics/feeds/data?ids=ga:1174&amp;ga:medium=referral&amp;ga:source=google.co.in&amp;filters=ga:medium%3D%3Dreferral&amp;start-date=2008-10-01&amp;end-date=2008-10-31</id>
+                <updated>2008-10-30T17:00:00.001-07:00</updated>
+                <title>ga:source=google.co.in | ga:medium=referral</title>
+                <link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
+                <dxp:dimension name='ga:source' value='google.co.in'/>
+                <dxp:dimension name='ga:medium' value='referral'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:visits' type='integer' value='2793'/>
+                <dxp:metric confidenceInterval='0.0' name='ga:bounces' type='integer' value='1891'/>
+        </entry>
+</feed>