You are here

class OfficialFacebookPixelInjection in Official Facebook Pixel 7

Same name and namespace in other branches
  1. 8 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 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() {
    $options = OfficialFacebookPixelOptions::getInstance();
    PixelScriptBuilder::initialize($options
      ->getPixelId());
    self::injectScriptCode($options);
    self::injectNoScriptCode();
    foreach (OfficialFacebookPixelConfig::integrationConfigFor7() as $key => $value) {
      $class_name = 'Drupal\\official_facebook_pixel\\integration\\' . $value;
      $class_name::injectPixelCode();
    }
  }
  public static function injectScriptCode($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();
    drupal_add_html_head([
      '#type' => 'markup',
      '#markup' => $pixel_script_code,
      '#weight' => 1000,
    ], 'facebook_pixel_script_code');
  }
  public static function injectNoScriptCode() {

    // Inject inline noscript code to head
    $pixel_noscript_code = PixelScriptBuilder::getPixelNoscriptCode();
    drupal_add_html_head([
      '#type' => 'markup',
      '#markup' => $pixel_noscript_code,
      '#weight' => 1000,
    ], 'facebook_pixel_noscript_code');
  }

}

Members