示例#1
0
 /**
  * Get metrics and dimension values for a configured stat
  *
  * TODO Catch "(403) Access Not Configured" (e.g. IP does not match)
  *
  * @param NodeInterface $node
  * @param ControllerContext $controllerContext
  * @param string $statIdentifier
  * @param \DateTime $startDate
  * @param \DateTime $endDate
  * @return DataResult
  * @throws MissingConfigurationException
  * @throws AnalyticsNotAvailableException
  */
 public function getNodeStat(NodeInterface $node, ControllerContext $controllerContext, $statIdentifier, \DateTime $startDate, \DateTime $endDate)
 {
     $this->analytics->requireAuthentication();
     if (!isset($this->statsSettings[$statIdentifier])) {
         throw new \InvalidArgumentException(sprintf('Unknown stat identifier "%s"', $statIdentifier), 1416917316);
     }
     $statConfiguration = $this->statsSettings[$statIdentifier];
     $siteConfiguration = $this->getSiteConfigurationByNode($node);
     $startDateFormatted = $startDate->format('Y-m-d');
     $endDateFormatted = $endDate->format('Y-m-d');
     $nodeUri = $this->getLiveNodeUri($node, $controllerContext);
     $filters = 'ga:pagePath==' . $nodeUri->getPath() . ';ga:hostname==' . $nodeUri->getHost();
     $gaResult = $this->analytics->data_ga->get('ga:' . $siteConfiguration->getProfileId(), $startDateFormatted, $endDateFormatted, $statConfiguration['metrics'], array('filters' => $filters, 'dimensions' => isset($statConfiguration['dimensions']) ? $statConfiguration['dimensions'] : ''));
     return new DataResult($gaResult);
 }
 /**
  * Get profiles grouped by account and webproperty
  *
  * TODO Handle "(403) User does not have any Google Analytics account."
  *
  * @return array
  */
 protected function getGroupedProfiles()
 {
     $this->analytics->requireAuthentication();
     $groupedProfiles = array();
     $accounts = $this->analytics->management_accounts->listManagementAccounts();
     foreach ($accounts as $account) {
         $groupedProfiles[$account->getId()]['label'] = $account->getName();
         $groupedProfiles[$account->getId()]['items'] = array();
     }
     $webproperties = $this->analytics->management_webproperties->listManagementWebproperties('~all');
     $webpropertiesById = array();
     foreach ($webproperties as $webproperty) {
         $webpropertiesById[$webproperty->getId()] = $webproperty;
     }
     $profiles = $this->analytics->management_profiles->listManagementProfiles('~all', '~all');
     foreach ($profiles as $profile) {
         if (isset($webpropertiesById[$profile->getWebpropertyId()])) {
             $webproperty = $webpropertiesById[$profile->getWebpropertyId()];
             $groupedProfiles[$profile->getAccountId()]['items'][$profile->getId()] = array('label' => $webproperty->getName() . ' > ' . $profile->getName(), 'value' => $profile->getId());
         }
     }
     return $groupedProfiles;
 }