You are here

function adsense_managed_init in Google AdSense integration 7

Implements hook_init().

File

managed/adsense_managed.module, line 19
Displays Google AdSense ads on Drupal pages.

Code

function adsense_managed_init() {
  if (variable_get('adsense_managed_page_level_ads_enabled', ADSENSE_MANAGED_PAGE_LEVEL_ADS_ENABLED)) {
    if (!_adsense_page_match()) {
      $script = '<!-- adsense auto ads: page not in match list -->';
    }
    elseif (!_adsense_check_if_enabled()) {
      $script = '<!-- adsense auto ads: ads disabled -->';
    }
    else {
      $client = adsense_get_client_slot_id();
      $script = <<<EOF
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-{<span class="php-variable">$client</span>}",
    enable_page_level_ads: true
  });
</script>
EOF;
    }
    $ad = array(
      '#type' => 'markup',
      '#markup' => $script,
      '#weight' => 100,
    );
    drupal_add_html_head($ad, 'adsense_managed_page_level_ad_script');
  }
}