You are here

class AmpAnalyticsService in Analytics 7

Hierarchy

Expanded class hierarchy of AmpAnalyticsService

1 string reference to 'AmpAnalyticsService'
analytics_amp_analytics_service_info in analytics_amp/analytics_amp.module
Implements hook_analytics_service_info().

File

analytics_amp/src/AmpAnalyticsService.php, line 3

View source
class AmpAnalyticsService extends AnalyticsService {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return array(
      'type' => NULL,
      'config_url' => '',
      'config_json' => array(),
      'data-credentials' => 0,
      'data-consent-notification-id' => '',
    );
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm($form, &$form_state) {
    $options['type'] = array(
      '#title' => t('Type'),
      '#type' => 'select',
      '#default_value' => $this
        ->getConfiguration()['type'],
      '#options' => array(
        // @todo Add support for all options.
        'adobeanalytics' => t('Adobe Analytics'),
        'googleanalytics' => t('Google Analytics'),
      ),
      '#required' => TRUE,
    );
    $options['config_url'] = array(
      '#title' => t('Remote configuration JSON URL'),
      '#type' => 'urlfield',
      '#default_value' => $this
        ->getConfiguration()['config_url'],
      '#placeholder' => 'https://example.com/analytics.config.json',
      '#element_validate' => array(
        'analytics_amp_element_validate_config_url',
      ),
    );
    $options['config_json'] = array(
      '#title' => t('Inline configuration JSON'),
      '#type' => 'textarea',
      '#default_value' => json_encode($this
        ->getConfiguration()['config_json'], JSON_PRETTY_PRINT | JSON_FORCE_OBJECT),
      '#element_validate' => array(
        'analytics_amp_element_validate_config_json',
      ),
    );
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function getOutput(array $context) {
    if (amp_is_amp_request()) {
      return $this
        ->getAmpOutput($this
        ->getConfiguration(), $context);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AmpAnalyticsService::buildConfigurationForm public function Form constructor. Overrides AnalyticsService::buildConfigurationForm
AmpAnalyticsService::defaultConfiguration public function Overrides AnalyticsService::defaultConfiguration
AmpAnalyticsService::getOutput public function Returns the output of the analytics service. Overrides AnalyticsServiceInterface::getOutput
AnalyticsService::$description private property
AnalyticsService::$hasMultiple protected property
AnalyticsService::$label private property
AnalyticsService::$machine_name private property
AnalyticsService::$options private property
AnalyticsService::$service private property
AnalyticsService::canTrack public function Determines if the current service can track the current request. Overrides AnalyticsServiceInterface::canTrack
AnalyticsService::getAmpOutput public function Build an <amp-analytics> tag for output on an amp-enabled page request.
AnalyticsService::getCacheableUrls public function Overrides AnalyticsServiceInterface::getCacheableUrls 2
AnalyticsService::getConfiguration public function Overrides AnalyticsServiceInterface::getConfiguration
AnalyticsService::getDescription public function Returns the description of the plugin instance. Overrides AnalyticsServiceInterface::getDescription
AnalyticsService::getLabel public function Returns the label of the plugin instance. Overrides AnalyticsServiceInterface::getLabel
AnalyticsService::getMachineName public function Returns the machine name of the analytics plugin instance. Overrides AnalyticsServiceInterface::getMachineName
AnalyticsService::getService public function Returns the type of the plugin instance. Overrides AnalyticsServiceInterface::getService
AnalyticsService::hasMultipleInstances public function
AnalyticsService::__construct public function