Skip to content

Commit 7951818

Browse files
committed
ADO-313: gets user data source url and other data from payload
1 parent a26b879 commit 7951818

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

app/code/Meta/Conversion/Helper/ServerEventFactory.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,24 @@ public function __construct(
6262
* @param string|null $eventId
6363
* @return Event
6464
*/
65-
public function newEvent($eventName, $eventId = null)
65+
public function newEvent($eventName, $additionalPayloadData, $eventId = null)
6666
{
6767
// Capture default user-data parameters passed down from the client browser.
68+
69+
$userAgent = $this->getValueOrFallback('user_agent', $additionalPayloadData, [Util::class, 'getHttpUserAgent']);
70+
$fbp = $this->getValueOrFallback('fbp', $additionalPayloadData, [Util::class, 'getFbp']);
71+
$fbc = $this->getValueOrFallback('fbc', $additionalPayloadData, [Util::class, 'getFbc']);
6872
$userData = (new UserData())
6973
->setClientIpAddress($this->getIpAddress())
70-
->setClientUserAgent(Util::getHttpUserAgent())
71-
->setFbp(Util::getFbp())
72-
->setFbc(Util::getFbc());
74+
->setClientUserAgent($userAgent)
75+
->setFbp($fbp)
76+
->setFbc($fbc);
7377

78+
$requestUri = $this->getValueOrFallback('request_uri', $additionalPayloadData, [Util::class, 'getRequestUri']);
7479
$event = (new Event())
7580
->setEventName($eventName)
7681
->setEventTime(time())
77-
->setEventSourceUrl(Util::getRequestUri())
82+
->setEventSourceUrl($requestUri)
7883
->setActionSource('website')
7984
->setUserData($userData)
8085
->setCustomData(new CustomData());
@@ -88,6 +93,11 @@ public function newEvent($eventName, $eventId = null)
8893
return $event;
8994
}
9095

96+
function getValueOrFallback($key, $data, $fallbackCallback)
97+
{
98+
return (!empty($data[$key])) ? $data[$key] : $fallbackCallback();
99+
}
100+
91101
/**
92102
* Get the IP address from the $_SERVER variable
93103
*
@@ -178,9 +188,9 @@ private function addCustomData($event, $data)
178188
* @param string|null $eventId
179189
* @return Event
180190
*/
181-
public function createEvent($eventName, $data, $eventId = null)
191+
public function createEvent($eventName, $data, $additionalPayloadData, $eventId = null)
182192
{
183-
$event = $this->newEvent($eventName, $eventId);
193+
$event = $this->newEvent($eventName, $additionalPayloadData, $eventId);
184194

185195
return $this->addCustomData($event, $data);
186196
}

0 commit comments

Comments
 (0)