GoogleAnalyticsGa.php in Analytics 8
File
analytics_google/src/Plugin/AnalyticsService/GoogleAnalyticsGa.php
View source
<?php
namespace Drupal\analytics_google\Plugin\AnalyticsService;
use Drupal\analytics\Plugin\ServicePluginBase;
use Drupal\Core\Form\FormStateInterface;
class GoogleAnalyticsGa extends ServicePluginBase {
public function defaultConfiguration() {
return [
'id' => NULL,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['id'] = [
'#type' => 'number',
'#title' => t('Tracking ID'),
'#default_value' => $this->configuration['id'],
'#min' => 0,
'#required' => TRUE,
'#size' => 15,
];
return $form;
}
public function getOutput() {
$output = [];
$output['analytics_' . $this
->getServiceId()] = [
'#type' => 'html_tag',
'#tag' => 'googleanalytics',
'#attributes' => [
'tracking_id' => $this->configuration['id'],
],
];
return $output;
}
}