You are here

public function OfficialFacebookPixelOptions::setUserInfo in Official Facebook Pixel 8

Same name and namespace in other branches
  1. 7 src/OfficialFacebookPixelOptions.php \Drupal\official_facebook_pixel\OfficialFacebookPixelOptions::setUserInfo()
1 call to OfficialFacebookPixelOptions::setUserInfo()
OfficialFacebookPixelOptions::__construct in src/OfficialFacebookPixelOptions.php

File

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

Class

OfficialFacebookPixelOptions
Class OfficialFacebookPixelOptions.

Namespace

Drupal\official_facebook_pixel

Code

public function setUserInfo() {
  $user = \Drupal::currentUser();
  $use_pii = $this
    ->getUsePii();
  if (0 === $user
    ->id() || $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
        ->getEmail(),
    ), function ($value) {
      return $value !== null && $value !== '';
    });
  }
}