You are here

class GoogleAnalyticsGaService in Analytics 7

Hierarchy

Expanded class hierarchy of GoogleAnalyticsGaService

1 string reference to 'GoogleAnalyticsGaService'
analytics_google_analytics_service_info in analytics_google/analytics_google.module
Implements hook_analytics_service_info().

File

analytics_google/src/GoogleAnalyticsGaService.php, line 3

View source
class GoogleAnalyticsGaService extends AnalyticsService {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return array(
      'id' => NULL,
    );
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm($form, &$form_state) {
    $options['id'] = array(
      '#title' => t('Tracking ID'),
      '#type' => 'textfield',
      '#default_value' => $this
        ->getConfiguration()['id'],
      '#element_validate' => array(
        '_analytics_google_validate_id',
      ),
      '#required' => TRUE,
      '#size' => 15,
    );
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function getOutput(array $context) {
    $actions = array();
    $actions[] = array(
      $this
        ->getMachineName() . '._setAccount',
      $this
        ->getConfiguration()['id'],
    );
    if (variable_get('analytics_privacy_anonymize_ip', FALSE)) {
      $actions[] = array(
        $this
          ->getMachineName() . '._anonymizeIp',
      );
    }
    $actions[] = array(
      $this
        ->getMachineName() . '._trackPageview',
    );
    $actions = array_merge($actions, module_invoke_all('analytics_google_ga_actions', $this, $context));
    drupal_alter('analytics_google_ga_actions', $actions, $this, $context);
    $output = array();
    $actions_code = theme('analytics_google_ga_actions_js', array(
      'actions' => $actions,
      'service' => $this,
    ));
    $output['#attached']['js'][] = array(
      'data' => $actions_code,
      'type' => 'inline',
      'preprocess' => FALSE,
      'scope' => 'footer',
    );
    static $added = FALSE;
    if (!$added) {
      $added = TRUE;
      $code = theme('analytics_google_ga_js', array(
        'service' => $this,
      ));
      $output['#attached']['js'][] = array(
        'data' => $code,
        'type' => 'inline',
        'weight' => 100000,
        'preprocess' => FALSE,
        'scope' => 'footer',
      );
    }
    return $output;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableUrls() {
    $urls = array();
    $urls[] = 'https://ssl.google-analytics.com/ga.js';
    return $urls;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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::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
GoogleAnalyticsGaService::buildConfigurationForm public function Form constructor. Overrides AnalyticsService::buildConfigurationForm
GoogleAnalyticsGaService::defaultConfiguration public function Overrides AnalyticsService::defaultConfiguration
GoogleAnalyticsGaService::getCacheableUrls public function Overrides AnalyticsService::getCacheableUrls
GoogleAnalyticsGaService::getOutput public function Returns the output of the analytics service. Overrides AnalyticsServiceInterface::getOutput