You are here

function hook_google_tag_snippets_alter in GoogleTagManager 8

Same name and namespace in other branches
  1. 7.2 google_tag.api.php \hook_google_tag_snippets_alter()
  2. 7 google_tag.api.php \hook_google_tag_snippets_alter()

Alter the snippets to be inserted on a page response.

This hook allows other modules to alter the snippets to be inserted based on custom settings not defined by this module.

Parameters

array $snippets: Associative array of snippets keyed by type: script, noscript and data_layer.

\Drupal\google_tag\Entity\Container $container: The associated container object.

1 invocation of hook_google_tag_snippets_alter()
Container::snippets in src/Entity/Container.php
Returns array of JavaScript snippets.

File

./google_tag.api.php, line 46
Hooks provided by this module.

Code

function hook_google_tag_snippets_alter(array &$snippets, Container $container) {

  // Do something to the script snippet.
  $snippets['script'] = str_replace('insertBefore', 'insertAfter', $snippets['script']);
}