You are here

function pardot_page_attachments in Pardot Integration 2.x

Same name and namespace in other branches
  1. 8 pardot.module \pardot_page_attachments()

Implements hook_page_attachments().

Adds Pardot tracking script with configuration settings when appropriate.

File

./pardot.module, line 100
Contains pardot.module.

Code

function pardot_page_attachments(array &$page) {

  // Get conditional state variable.
  // @see \Drupal\pardot\EventSubscriber\PardotEventSubscriber
  $include_tracking = (bool) \Drupal::state()
    ->get('pardot.include_tracking') ?: 0;
  $config = \Drupal::config('pardot.settings');
  if ($include_tracking && $config
    ->get('account_id') !== NULL) {

    // Use default campaign ID.
    $campaign_id = $config
      ->get('default_campaign_id');
    $page['#attached']['drupalSettings']['pardot']['accountId'] = $config
      ->get('account_id');
    $page['#attached']['drupalSettings']['pardot']['campaignId'] = $campaign_id;
    $page['#attached']['library'][] = 'pardot/pardot';
  }
}