Analytics.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Analytics
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Gdata
  24. */
  25. require_once 'Zend/Gdata.php';
  26. /**
  27. * @see Zend_Gdata_Analytics_AccountEntry
  28. */
  29. require_once 'Zend/Gdata/Analytics/AccountEntry.php';
  30. /**
  31. * @see Zend_Gdata_Analytics_AccountFeed
  32. */
  33. require_once 'Zend/Gdata/Analytics/AccountFeed.php';
  34. /**
  35. * @see Zend_Gdata_Analytics_DataEntry
  36. */
  37. require_once 'Zend/Gdata/Analytics/DataEntry.php';
  38. /**
  39. * @see Zend_Gdata_Analytics_DataFeed
  40. */
  41. require_once 'Zend/Gdata/Analytics/DataFeed.php';
  42. /**
  43. * @see Zend_Gdata_Analytics_DataQuery
  44. */
  45. require_once 'Zend/Gdata/Analytics/DataQuery.php';
  46. /**
  47. * @category Zend
  48. * @package Zend_Gdata
  49. * @subpackage Analytics
  50. */
  51. class Zend_Gdata_Analytics extends Zend_Gdata
  52. {
  53. const AUTH_SERVICE_NAME = 'analytics';
  54. const ANALYTICS_FEED_URI = 'https://www.google.com/analytics/feeds';
  55. const ANALYTICS_ACCOUNT_FEED_URI = 'https://www.google.com/analytics/feeds/accounts';
  56. public static $namespaces = array(
  57. array('ga', 'http://schemas.google.com/analytics/2009', 1, 0)
  58. );
  59. /**
  60. * Create Gdata object
  61. *
  62. * @param Zend_Http_Client $client
  63. * @param string $applicationId The identity of the app in the form of
  64. * Company-AppName-Version
  65. */
  66. public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
  67. {
  68. $this->registerPackage('Zend_Gdata_Analytics');
  69. $this->registerPackage('Zend_Gdata_Analytics_Extension');
  70. parent::__construct($client, $applicationId);
  71. $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
  72. }
  73. /**
  74. * Retrieve account feed object
  75. *
  76. * @return Zend_Gdata_Analytics_AccountFeed
  77. */
  78. public function getAccountFeed()
  79. {
  80. $uri = self::ANALYTICS_ACCOUNT_FEED_URI . '/default?prettyprint=true';
  81. return parent::getFeed($uri, 'Zend_Gdata_Analytics_AccountFeed');
  82. }
  83. /**
  84. * Retrieve data feed object
  85. *
  86. * @param mixed $location
  87. * @return Zend_Gdata_Analytics_DataFeed
  88. */
  89. public function getDataFeed($location)
  90. {
  91. if ($location == null) {
  92. $uri = self::ANALYTICS_FEED_URI;
  93. } elseif ($location instanceof Zend_Gdata_Query) {
  94. $uri = $location->getQueryUrl();
  95. } else {
  96. $uri = $location;
  97. }
  98. return parent::getFeed($uri, 'Zend_Gdata_Analytics_DataFeed');
  99. }
  100. /**
  101. * Returns a new DataQuery object.
  102. *
  103. * @return Zend_Gdata_Analytics_DataQuery
  104. */
  105. public function newDataQuery()
  106. {
  107. return new Zend_Gdata_Analytics_DataQuery();
  108. }
  109. }