Skip to content

Commit

Permalink
Add support for Pardot tracking cookies for Form Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Dec 27, 2024
1 parent bf66c26 commit f197a8a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/integrations/crm/Pardot.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,23 @@ public function getClient(): Client
return $this->_client;
}

public function populateContext(): void
{
parent::populateContext();

// Allow us to save the tracking cookie at the time of submission, so grab later
$trackingData = [];
$pattern = '/^visitor_id[0-9]+(-hash)?$/';

foreach ($_COOKIE as $key => $value) {
if (preg_match($pattern, $key)) {
$trackingData[$key] = $value;
}
}

$this->context['pardot_tracking'] = $trackingData;
}


// Protected Methods
// =========================================================================
Expand All @@ -568,6 +585,10 @@ protected function generatePayloadValues(Submission $submission): array
// Flatten array to dot-notation
$payload = ArrayHelper::flatten($payload);

// Add in cookie tracking support, if available
$trackingData = $this->context['pardot_tracking'] ?? [];
$payload = array_merge($payload, $trackingData);

// Fire a 'modifyPayload' event
$event = new ModifyPayloadEvent([
'submission' => $submission,
Expand Down

0 comments on commit f197a8a

Please sign in to comment.