You are here

function poptin_page_attachments in Website Popups, Email Popup, Exit-Intent Popup, and Contact Forms – Poptin 8

Implements hook_page_attachments().

File

./poptin.module, line 64
Module for adding popups on website.

Code

function poptin_page_attachments(array &$attachments) {
  if (!\Drupal::service('router.admin_context')
    ->isAdminRoute()) {
    $poptin_db = poptin_fetch_row();
    if (is_array($poptin_db) && isset($poptin_db['client_id']) && $poptin_db['client_id'] != '') {
      $client_id = Html::escape($poptin_db['client_id']);
      $attachments['#attached']['html_head'][] = [
        [
          '#type' => 'html_tag',
          '#tag' => 'script',
          '#attributes' => [
            'src' => 'https://cdn.popt.in/pixel.js?id=' . $client_id,
            'async' => 'true',
            'id' => 'pixel-script-poptin',
          ],
        ],
        'poptin',
      ];
    }
  }
}