function ga_page_attachments in Googalytics - Google Analytics 8
Implements hook_page_attachments().
File
Code
function ga_page_attachments(array &$attachments) {
// Don't execute until gacsp module is uninstalled.
if (\Drupal::moduleHandler()
->moduleExists('gacsp')) {
return;
}
/** @var \Drupal\ga\Event\CollectEvent $event */
$event = \Drupal::service('event_dispatcher')
->dispatch(AnalyticsEvents::COLLECT, new CollectEvent());
$commands = $event
->getDrupalSettingCommands();
if (!empty($commands)) {
$attachments['#attached']['library'][] = 'ga/analytics';
$attachments['#attached']['drupalSettings']['ga']['commands'] = $commands;
}
}