You are here

class OfficialFacebookPixelInjection in Official Facebook Pixel 8

Same name and namespace in other branches
  1. 7 src/OfficialFacebookPixelInjection.php \Drupal\official_facebook_pixel\OfficialFacebookPixelInjection

Class OfficialFacebookPixelInjection.

@package Drupal\official_facebook_pixel

Hierarchy

Expanded class hierarchy of OfficialFacebookPixelInjection

1 file declares its use of OfficialFacebookPixelInjection
official_facebook_pixel.module in ./official_facebook_pixel.module
Contains official_facebook_pixel.module.

File

src/OfficialFacebookPixelInjection.php, line 31
Contains \Drupal\official_facebook_pixel \OfficialFacebookPixelInjection.

Namespace

Drupal\official_facebook_pixel
View source
class OfficialFacebookPixelInjection {
  public static function injectPixelCode(array &$page) {
    $options = OfficialFacebookPixelOptions::getInstance();
    PixelScriptBuilder::initialize($options
      ->getPixelId());
    self::injectScriptCode($page, $options);
    self::injectNoScriptCode($page);
    foreach (OfficialFacebookPixelConfig::integrationConfigFor8() as $key => $value) {
      $class_name = 'Drupal\\official_facebook_pixel\\integration\\' . $value;
      $class_name::injectPixelCode($page);
    }
  }
  public static function injectScriptCode(array &$page, $options) {

    // Inject inline script code to head
    $pixel_script_code = PixelScriptBuilder::getPixelBaseCode();
    $pixel_script_code .= PixelScriptBuilder::getPixelInitCode($options
      ->getAgentString(), $options
      ->getUserInfo());
    $pixel_script_code .= PixelScriptBuilder::getPixelPageViewCode();
    $page['#attached']['html_head'][] = [
      [
        '#tag' => 'script',
        '#value' => $pixel_script_code,
      ],
      'facebook_pixel_script_code',
    ];
  }
  public static function injectNoScriptCode(array &$page) {

    // Inject inline noscript code to head
    $pixel_noscript_code = PixelScriptBuilder::getPixelNoscriptCode();
    $page['#attached']['html_head'][] = [
      [
        '#tag' => 'noscript',
        '#value' => $pixel_noscript_code,
      ],
      'facebook_pixel_noscript_code',
    ];
  }

}

Members