You are here

function ga_push_page_attachments in GA Push 8

Implements hook_page_attachments().

File

./ga_push.module, line 70
Drupal Module: GA Push.

Code

function ga_push_page_attachments(array &$attachments) {
  $script = NULL;
  module_load_include('inc', 'ga_push', 'inc/ga_push.ga_js');
  $ga_js_push = ga_push_method_ga_js_push();
  $script .= $ga_js_push;
  module_load_include('inc', 'ga_push', 'inc/ga_push.analytics_js');
  $analytics_js_push = ga_push_method_analytics_js_push();
  $script .= $analytics_js_push;
  module_load_include('inc', 'ga_push', 'inc/ga_push.datalayer');
  $datalayer_push = ga_push_method_datalayer_push();
  $script .= $datalayer_push;

  // Add JS headers:
  if (!empty($script)) {
    $attachments['#attached']['html_head'][] = [
      [
        '#tag' => 'script',
        '#value' => $script,
        // It must load after GA Module.
        '#weight' => 10,
      ],
      'ga_push_tracking_script',
    ];
  }
}