View source
<?php
class AmpAnalyticsService extends AnalyticsService {
public function defaultConfiguration() {
return array(
'type' => NULL,
'config_url' => '',
'config_json' => array(),
'data-credentials' => 0,
'data-consent-notification-id' => '',
);
}
public function buildConfigurationForm($form, &$form_state) {
$options['type'] = array(
'#title' => t('Type'),
'#type' => 'select',
'#default_value' => $this
->getConfiguration()['type'],
'#options' => array(
'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;
}
public function getOutput(array $context) {
if (amp_is_amp_request()) {
return $this
->getAmpOutput($this
->getConfiguration(), $context);
}
}
}