You are here

class OfficialFacebookPixelOptions in Official Facebook Pixel 7

Same name and namespace in other branches
  1. 8 src/OfficialFacebookPixelOptions.php \Drupal\official_facebook_pixel\OfficialFacebookPixelOptions

Class OfficialFacebookPixelOptions.

@package Drupal\official_facebook_pixel

Hierarchy

Expanded class hierarchy of OfficialFacebookPixelOptions

3 files declare their use of OfficialFacebookPixelOptions
OfficialFacebookPixelInjection.php in src/OfficialFacebookPixelInjection.php
Contains \Drupal\official_facebook_pixel \OfficialFacebookPixelInjection.
official_facebook_pixel.admin.inc in ./official_facebook_pixel.admin.inc
Contains facebook_pixel_settings_form.
official_facebook_pixel.module in ./official_facebook_pixel.module
Contains facebook_pixel.module.

File

src/OfficialFacebookPixelOptions.php, line 30
Contains \Drupal\official_facebook_pixel \OfficialFacebookPixelOptions.

Namespace

Drupal\official_facebook_pixel
View source
class OfficialFacebookPixelOptions {
  private static $instance = null;
  private $options = array();
  private $userInfo = array();
  private $versionInfo = array();
  public static function getInstance() {
    if (is_null(self::$instance)) {
      self::$instance = new OfficialFacebookPixelOptions();
    }
    return self::$instance;
  }
  public function __construct() {
    $this
      ->setOptions();
    $this
      ->setUserInfo();
    $this
      ->setVersionInfo();
  }
  public function getOptions() {
    return $this->options;
  }
  private function setOptions() {
    $this->options = array(
      OfficialFacebookPixelConfig::FORM_PIXEL_KEY => variable_get(OfficialFacebookPixelConfig::FORM_PIXEL_KEY, '{pixel_id}'),
      OfficialFacebookPixelConfig::FORM_PII_KEY => variable_get(OfficialFacebookPixelConfig::FORM_PII_KEY, 1),
    );
  }
  public function getPixelId() {
    return $this->options[OfficialFacebookPixelConfig::FORM_PIXEL_KEY];
  }
  public function getUsePii() {
    return $this->options[OfficialFacebookPixelConfig::FORM_PII_KEY];
  }
  public function getUserInfo() {
    return $this->userInfo;
  }
  public function setUserInfo() {
    global $user;
    $use_pii = $this
      ->getUsePii();
    if (0 === $user->uid || $use_pii !== 1) {

      // User not logged in or admin chose not to send PII.
      $this->userInfo = array();
    }
    else {
      $this->userInfo = array_filter(array(
        // Keys documented in
        // https://developers.facebook.com/docs/facebook-pixel/pixel-with-ads/conversion-tracking#advanced_match
        'em' => $user->mail,
      ), function ($value) {
        return $value !== null && $value !== '';
      });
    }
  }
  public function getVersionInfo() {
    return $this->versionInfo;
  }
  public function setVersionInfo() {
    $this->versionInfo = array(
      'source' => OfficialFacebookPixelConfig::SOURCE_7,
      'version' => VERSION,
    );
  }
  public function getAgentString() {
    return sprintf('%s-%s', $this->versionInfo['source'], $this->versionInfo['version']);
  }

}

Members