You are here

function d8_google_optimize_hide_page_page_attachments_alter in Drupal 8 Google Optimize Hide Page 8

Implements hook_page_attachments_alter().

Change datalayer and google_tag JS scripts weight.

File

./d8_google_optimize_hide_page.module, line 254
d8_google_optimize_hide_page.module

Code

function d8_google_optimize_hide_page_page_attachments_alter(array &$attachments) {
  foreach ($attachments['#attached']['html_head'] as $key => $attachment) {
    if ($attachment[1] === 'datalayers-js') {
      $attachments['#attached']['html_head'][$key][0]['#weight'] = -17;
    }
    if (strpos($attachment[1], 'google_tag_script_tag') === 0) {
      $attachments['#attached']['html_head'][$key][0]['#weight'] = -14;
    }
  }
}