You are here

function cookies_matomo_page_attachments in COOKiES Consent Management 1.0.x

Implements hook_page_attachments().

File

modules/cookies_matomo/cookies_matomo.module, line 31
Contains cookies_matomo.module.

Code

function cookies_matomo_page_attachments(&$page) {
  $doKo = CookiesKnockOutService::getInstance()
    ->doKnockOut();
  if ($doKo) {
    foreach ($page["#attached"]["html_head"] as $key => $head_tag) {
      if (in_array('matomo_tracking_script', $head_tag)) {
        $attr = isset($head_tag[0]['#attributes']) ? $head_tag[0]['#attributes'] : [];
        $attr = array_merge($attr, [
          'type' => 'application/json',
          'id' => 'cookies_matomo',
        ]);
        $page["#attached"]["html_head"][$key][0]['#attributes'] = new Attribute($attr);
        $page["#attached"]["library"][] = 'cookies_matomo/analytics';
        break;
      }
    }
  }
}