You are here

public function GoogleAnalyticsCounterAuthManager::getWebPropertiesOptions in Google Analytics Counter 8.3

Get the list of available web properties.

Return value

array Array of options.

Overrides GoogleAnalyticsCounterAuthManagerInterface::getWebPropertiesOptions

File

src/GoogleAnalyticsCounterAuthManager.php, line 167

Class

GoogleAnalyticsCounterAuthManager
Class GoogleAnalyticsAuthManager.

Namespace

Drupal\google_analytics_counter

Code

public function getWebPropertiesOptions() {

  // When not authenticated of if there are no Analytics, no options will be displayed.
  $feed = $this
    ->newGaFeed();
  if (!$feed) {
    $options = [
      'unauthenticated' => '',
    ];
    return $options;
  }

  // Check for web properties.
  if (isset($feed
    ->queryWebProperties()->results->items)) {
    $web_properties = $feed
      ->queryWebProperties()->results->items;
    $profiles = $feed
      ->queryProfiles()->results->items;
  }
  $options = [];

  // Add options for each web property.
  if (!empty($profiles)) {
    foreach ($profiles as $profile) {
      $webprop = NULL;
      foreach ($web_properties as $web_property) {
        if ($web_property->id == $profile->webPropertyId) {
          $webprop = $web_property;
          break;
        }
      }
      $options[$webprop->name][$profile->id] = $profile->name . ' (' . $profile->id . ')';
    }
  }
  return $options;
}