You are here

AmpAnalyticsService.php in Analytics 7

File

analytics_amp/src/AmpAnalyticsService.php
View source
<?php

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);
    }
  }

}

Classes