You are here

public function PardotClient::getVisitorId in Pardot Integration 2.x

Gets current user's visitor ID.

Return value

null|string The cookie value if it exists, NULL otherwise.

File

src/Service/PardotClient.php, line 317

Class

PardotClient
Provides methods to execute Pardot API operations.

Namespace

Drupal\pardot\Service

Code

public function getVisitorId() {

  // maybe better way of doing it.
  //    $cookies = \Drupal::request()->cookies->all();
  //    foreach ($cookies as $cookie_name => $cookie_value) {
  //      if (preg_match('/visitor_id\d+$/', $cookie_name)) {
  //        $visitor_id = $cookie_value;
  //        break;
  //      }
  //    }
  // Get Pardot piAId.
  $account_id = $this->pardotSettings
    ->get('account_id');

  // Visitor cookie ID is account ID - 1000, for some reason.
  $cookie_name = 'visitor_id' . ((int) $account_id - 1000);
  if (isset($_COOKIE[$cookie_name])) {
    return $_COOKIE[$cookie_name];
  }
  return NULL;
}