You are here

function linkedin_insights_tag_page_bottom in LinkedIn Insights Tag 8

Implements hook_page_bottom().

File

./linkedin_insights_tag.module, line 48
LinkedIn Insights Module..

Code

function linkedin_insights_tag_page_bottom(array &$page_bottom) {

  // Get config.
  $config = \Drupal::config('linkedin_insights_tag.settings');
  $pid = $config
    ->get('partner_id');

  // If image_only is false, then placement should be in a noscript tag.
  // If image_only is true, do not wrap in a noscript tag.
  $noscript = !$config
    ->get('image_only');
  if (!empty($pid)) {
    $img_src = 'https://dc.ads.linkedin.com/collect/?pid=' . $pid . '&fmt=gif';

    // Validate url.
    if (UrlHelper::isValid($img_src, TRUE)) {

      // Add noscript support.
      $page_bottom[] = [
        'img_tag' => [
          '#type' => 'html_tag',
          '#tag' => 'img',
          '#noscript' => $noscript,
          '#attributes' => [
            'height' => 1,
            'width' => 1,
            'alt' => '',
            'style' => 'display:none',
            'src' => $img_src,
          ],
        ],
      ];
    }
  }
}