diff options
Diffstat (limited to 'zend/library/Zend/Gdata/Analytics')
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/AccountEntry.php | 102 | ||||
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/AccountFeed.php | 57 | ||||
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/AccountQuery.php | 190 | ||||
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/DataEntry.php | 116 | ||||
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/DataFeed.php | 64 | ||||
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/DataQuery.php | 403 | ||||
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/Extension/Dimension.php | 40 | ||||
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/Extension/Goal.php | 52 | ||||
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/Extension/Metric.php | 54 | ||||
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/Extension/Property.php | 122 | ||||
| -rw-r--r-- | zend/library/Zend/Gdata/Analytics/Extension/TableId.php | 112 |
11 files changed, 1312 insertions, 0 deletions
diff --git a/zend/library/Zend/Gdata/Analytics/AccountEntry.php b/zend/library/Zend/Gdata/Analytics/AccountEntry.php new file mode 100644 index 0000000..c709bb7 --- /dev/null +++ b/zend/library/Zend/Gdata/Analytics/AccountEntry.php @@ -0,0 +1,102 @@ +<?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; + protected $_profileName; + protected $_goal; + + /** + * @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('analytics') . ':' . 'property'; + $property = new Zend_Gdata_Analytics_Extension_Property(); + $property->transferFromDOM($child); + $this->{$property->getName()} = $property; + break; + case $this->lookupNamespace('analytics') . ':' . 'tableId'; + $tableId = new Zend_Gdata_Analytics_Extension_TableId(); + $tableId->transferFromDOM($child); + $this->_tableId = $tableId; + break; + case $this->lookupNamespace('ga') . ':' . 'goal'; + $goal = new Zend_Gdata_Analytics_Extension_Goal(); + $goal->transferFromDOM($child); + $this->_goal = $goal; + break; + default: + parent::takeChildFromDOM($child); + break; + } + } +} diff --git a/zend/library/Zend/Gdata/Analytics/AccountFeed.php b/zend/library/Zend/Gdata/Analytics/AccountFeed.php new file mode 100644 index 0000000..b0e81a6 --- /dev/null +++ b/zend/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); + } +} diff --git a/zend/library/Zend/Gdata/Analytics/AccountQuery.php b/zend/library/Zend/Gdata/Analytics/AccountQuery.php new file mode 100644 index 0000000..6d8dbdc --- /dev/null +++ b/zend/library/Zend/Gdata/Analytics/AccountQuery.php @@ -0,0 +1,190 @@ +<?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_AccountQuery extends Zend_Gdata_Query +{ + const ANALYTICS_FEED_URI = 'https://www.googleapis.com/analytics/v2.4/management/accounts'; + + /** + * The default URI used for feeds. + */ + protected $_defaultFeedUri = self::ANALYTICS_FEED_URI; + + /** + * @var string + */ + protected $_accountId = '~all'; + /** + * @var string + */ + protected $_webpropertyId = '~all'; + /** + * @var string + */ + protected $_profileId = '~all'; + + /** + * @var bool + */ + protected $_webproperties = false; + /** + * @var bool + */ + protected $_profiles = false; + /** + * @var bool + */ + protected $_goals = false; + + /** + * @param string $accountId + * @return Zend_Gdata_Analytics_AccountQuery + */ + public function setAccountId($accountId) + { + $this->_accountId = $accountId; + return $this; + } + + /** + * @return string + */ + public function getAccountId() + { + return $this->_accountId; + } + + /** + * @param string $webpropertyId + * @return Zend_Gdata_Analytics_AccountQuery + */ + public function setWebpropertyId($webpropertyId) + { + $this->_webpropertyId = $webpropertyId; + return $this; + } + + /** + * @return string + */ + public function getWebpropertyId() + { + return $this->_webpropertyId; + } + + /** + * @param string $profileId + * @return Zend_Gdata_Analytics_AccountQuery + */ + public function setProfileId($profileId) + { + $this->_profileId = $profileId; + return $this; + } + + /** + * @return string + */ + public function getProfileId() + { + return $this->_profileId; + } + + /** + * @param string $accountId + * @return Zend_Gdata_Analytics_AccountQuery + */ + public function webproperties($accountId = '~all') + { + $this->_webproperties = true; + $this->setAccountId($accountId); + return $this; + } + + /** + * @param string $webpropertyId + * @param string $accountId + * @return Zend_Gdata_Analytics_AccountQuery + */ + public function profiles($webpropertyId = '~all', $accountId = '~all') + { + $this->_profiles = true; + if (null !== $accountId) { + $this->setAccountId($accountId); + } + $this->setWebpropertyId($webpropertyId); + return $this; + } + + /** + * @param string $webpropertyId + * @param string $accountId + * @param string $accountId + * @return Zend_Gdata_Analytics_AccountQuery + */ + public function goals($profileId = '~all', $webpropertyId = '~all', $accountId = '~all') + { + $this->_goals = true; + if (null !== $accountId) { + $this->setAccountId($accountId); + } + if (null !== $webpropertyId) { + $this->setWebpropertyId($webpropertyId); + } + $this->setProfileId($profileId); + return $this; + } + + /** + * @return string url + */ + public function getQueryUrl() + { + $url = $this->_defaultFeedUri; + + // add account id + if ($this->_webproperties or $this->_profiles or $this->_goals) { + $url .= '/' . $this->_accountId . '/webproperties'; + } + + if ($this->_profiles or $this->_goals) { + $url .= '/' . $this->_webpropertyId . '/profiles'; + } + + if ($this->_goals) { + $url .= '/' . $this->_profileId . '/goals'; + } + + $url .= $this->getQueryString(); + return $url; + } +}
\ No newline at end of file diff --git a/zend/library/Zend/Gdata/Analytics/DataEntry.php b/zend/library/Zend/Gdata/Analytics/DataEntry.php new file mode 100644 index 0000000..a0ccb81 --- /dev/null +++ b/zend/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('analytics') . ':' . 'dimension'; + $dimension = new Zend_Gdata_Analytics_Extension_Dimension(); + $dimension->transferFromDOM($child); + $this->_dimensions[] = $dimension; + break; + case $this->lookupNamespace('analytics') . ':' . '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); + } +} diff --git a/zend/library/Zend/Gdata/Analytics/DataFeed.php b/zend/library/Zend/Gdata/Analytics/DataFeed.php new file mode 100644 index 0000000..42e3156 --- /dev/null +++ b/zend/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); + } +} diff --git a/zend/library/Zend/Gdata/Analytics/DataQuery.php b/zend/library/Zend/Gdata/Analytics/DataQuery.php new file mode 100644 index 0000000..51c9e5c --- /dev/null +++ b/zend/library/Zend/Gdata/Analytics/DataQuery.php @@ -0,0 +1,403 @@ +<?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 = 'https://www.googleapis.com/analytics/v2.4/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; + } + + /** + * @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; + } + + /** + * @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; + } +} diff --git a/zend/library/Zend/Gdata/Analytics/Extension/Dimension.php b/zend/library/Zend/Gdata/Analytics/Extension/Dimension.php new file mode 100644 index 0000000..1c61728 --- /dev/null +++ b/zend/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; +} diff --git a/zend/library/Zend/Gdata/Analytics/Extension/Goal.php b/zend/library/Zend/Gdata/Analytics/Extension/Goal.php new file mode 100644 index 0000000..f1e5cb8 --- /dev/null +++ b/zend/library/Zend/Gdata/Analytics/Extension/Goal.php @@ -0,0 +1,52 @@ +<?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_Goal extends Zend_Gdata_Extension +{ + protected $_rootNamespace = 'ga'; + protected $_rootElement = 'goal'; + + public function __construct() + { + $this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces); + parent::__construct(); + } + + /** + * @return string + */ + public function __toString() + { + $attribs = $this->getExtensionAttributes(); + return $attribs['name']['value']; + } +} diff --git a/zend/library/Zend/Gdata/Analytics/Extension/Metric.php b/zend/library/Zend/Gdata/Analytics/Extension/Metric.php new file mode 100644 index 0000000..6aa399c --- /dev/null +++ b/zend/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); + } + } +} diff --git a/zend/library/Zend/Gdata/Analytics/Extension/Property.php b/zend/library/Zend/Gdata/Analytics/Extension/Property.php new file mode 100644 index 0000000..4788bf6 --- /dev/null +++ b/zend/library/Zend/Gdata/Analytics/Extension/Property.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_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': + $name = explode(':', $attribute->nodeValue); + $this->_name = end($name); + 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(); + } +} diff --git a/zend/library/Zend/Gdata/Analytics/Extension/TableId.php b/zend/library/Zend/Gdata/Analytics/Extension/TableId.php new file mode 100644 index 0000000..f1ddad5 --- /dev/null +++ b/zend/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(); + } +} |
