You are here

function dfp_preprocess_html in Doubleclick for Publishers (DFP) 7.2

Same name and namespace in other branches
  1. 7 dfp.module \dfp_preprocess_html()

Implements hook_preprocess_HOOK().

File

./dfp.module, line 365

Code

function dfp_preprocess_html(&$variables) {

  // Can be overridden in global settings.
  $ignore_admin = variable_get('dfp_gtm_admin_pages', TRUE);
  if ($ignore_admin) {

    // Check for admin page.
    $is_admin = path_is_admin(current_path());
    if ($is_admin) {
      return;
    }
  }

  // Allows using google tag manager.
  $gtm_container_id = variable_get('dfp_gtm_container_id', '');
  if (!empty($gtm_container_id)) {

    // Google Tag Manager.
    $google_tag = array(
      '#tag' => 'script',
      '#attributes' => array(
        'type' => 'text/javascript',
      ),
      '#weight' => -100,
      '#value' => "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push(\n{'gtm.start': new Date().getTime(),event:'gtm.js'}\n);var f=d.getElementsByTagName(s)[0],\nj=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n})(window,document,'script','dataLayer','GTM-" . $gtm_container_id . "');",
    );
    drupal_add_html_head($google_tag, 'dfp_google_tag_manager');

    // Google Tag Manager (noscript). This should probably be in its own
    // template.
    $src = "https://www.googletagmanager.com/ns.html?id=GTM-" . $gtm_container_id;
    $variables['google_tag_iframe'] = '<noscript><iframe src="' . $src . '"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>';
  }

  // Add the header js here so that enough information has been loaded for
  // tokens to work properly.
  _dfp_js_global_settings();
}