AmpTrackingPixelAnalyticsService.php in Analytics 7
File
analytics_amp/src/AmpTrackingPixelAnalyticsService.php
View source
<?php
class AmpTrackingPixelAnalyticsService extends AnalyticsService {
public function defaultConfiguration() {
return array(
'url' => '',
);
}
public function buildConfigurationForm($form, &$form_state) {
$options['url'] = array(
'#title' => t('URL'),
'#type' => 'urlfield',
'#default_value' => $this
->getConfiguration()['url'],
'#description' => t('See the <a href="@url">substitutions guide</a> to see what variables can be included in the URL.', array(
'@url' => 'https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md',
)),
'#required' => TRUE,
'#placeholder' => 'https://foo.com/pixel?RANDOM',
);
return $options;
}
public function getOutput(array $context) {
if (amp_is_amp_request()) {
return array(
'#theme' => 'html_tag',
'#tag' => 'amp-pixel',
'#attributes' => array(
'id' => drupal_html_id('analytics_' . $this
->getMachineName()),
'src' => $this
->getConfiguration()['url'],
),
);
}
}
}