You are here

function crazyegg_page_attachments in Crazy Egg Integration 8

Implements hook_page_attachments(). Checks all conditions and if they are met, injects Crazy Egg tracking script into the page

File

./crazyegg.module, line 77

Code

function crazyegg_page_attachments(array &$attachments) {
  $crazyegg_enabled = \Drupal::config('crazyegg.settings')
    ->get('crazyegg_enabled');
  $account_path = crazyegg_get_account_path();

  // if module is enabled, there is an account ID, user role is allowed and current page matches page targeting setting
  if ($crazyegg_enabled > 0 && $account_path && crazyegg_is_page_allowed() && crazyegg_is_role_allowed()) {
    $attachments['#attached']['library'][] = 'crazyegg/crazyegg';
  }
}