public function AnalyticsSubscriber::onCollectGlobalProperties in Googalytics - Google Analytics 8
Add global dimensions and metrics.
Parameters
\Drupal\ga\Event\CollectEvent $event: The AnalyticsEvents::COLLECT event.
File
- modules/
ga_tokens/ src/ EventSubscriber/ AnalyticsSubscriber.php, line 65
Class
- AnalyticsSubscriber
- Class DefaultCommandSubscriber.
Namespace
Drupal\ga_tokens\EventSubscriberCode
public function onCollectGlobalProperties(CollectEvent $event) {
$config = $this->configFactory
->get('ga_tokens.global');
$dimensions = $config
->get('dimensions') ?: [];
foreach ($dimensions as $index => $dimension) {
$value = $this->token
->replace($dimension['value']);
$event
->addCommand(new Dimension($index, $value));
}
$metrics = $config
->get('metrics') ?: [];
foreach ($metrics as $index => $metric) {
$value = $this->token
->replace($metric['value']);
$event
->addCommand(new Metric($index, $value));
}
}