commerce_google_tag_manager.module in Commerce Google Tag Manager 8.2
Same filename and directory in other branches
Module file for the commerce_google_tag_manager module.
File
commerce_google_tag_manager.moduleView source
<?php
/**
* @file
* Module file for the commerce_google_tag_manager module.
*/
use Drupal\Core\Cache\CacheableMetadata;
/**
* Pass module configuration to javascript.
*
* Implements hook_page_attachments().
*/
function commerce_google_tag_manager_page_attachments(array &$page) {
$page['#attached']['library'][] = 'commerce_google_tag_manager/commerce_google_tag_manager';
$page['#attached']['drupalSettings']['commerceGoogleTagManager'] = [
'eventsUrl' => Drupal::service('url_generator')
->generateFromRoute('commerce_google_tag_manager.events'),
'dataLayerVariable' => Drupal::config('google_tag.settings')
->get('data_layer') ?: 'dataLayer',
];
// Add cache metadata to the render array.
$cache = new CacheableMetadata();
$cache
->addCacheableDependency(Drupal::config('google_tag.settings'));
$cache
->applyTo($page);
}
Functions
Name![]() |
Description |
---|---|
commerce_google_tag_manager_page_attachments | Pass module configuration to javascript. |