Skip to content

Commit 3747622

Browse files
authored
issue-resolution/server event additional fields (#172)
1 parent 1585723 commit 3747622

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

app/code/Meta/Conversion/Controller/Pixel/Tracker.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public function execute(): Json
7979
if ($eventName) {
8080
$payload = $this->pixelEvents[$eventName]->getPayload($params);
8181
if (count($payload)) {
82+
// Add source and pluginVersion in the payload as custom properties
83+
$payload['custom_properties'] = [];
84+
$payload['custom_properties']['source'] = $this->fbeHelper->getSource();
85+
$payload['custom_properties']['pluginVersion'] = $this->fbeHelper->getPluginVersion();
86+
8287
$eventType = $this->pixelEvents[$eventName]->getEventType();
8388

8489
$event = ServerEventFactory::createEvent($eventType, array_filter($payload), $eventId);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ private static function addCustomData($event, $data)
162162
$custom_data->setOrderId($data['order_id']);
163163
}
164164

165+
if (!empty($data['custom_properties']) && is_array($data['custom_properties'])) {
166+
$custom_data->setCustomProperties($data['custom_properties']);
167+
}
168+
165169
return $event;
166170
}
167171

app/code/Meta/Conversion/Observer/AddToCart.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ public function execute(Observer $observer)
101101
'content_type' => $this->magentoDataHelper->getContentType($product),
102102
'content_ids' => [$this->magentoDataHelper->getContentId($product)],
103103
'content_category' => $this->magentoDataHelper->getCategoriesForProduct($product),
104-
'content_name' => $this->escaper->escapeUrl($product->getName())
104+
'content_name' => $this->escaper->escapeUrl($product->getName()),
105+
'custom_properties' => [
106+
'source' => $this->fbeHelper->getSource(),
107+
'pluginVersion' => $this->fbeHelper->getPluginVersion()
108+
]
105109
];
106110
$event = ServerEventFactory::createEvent('AddToCart', $customData, $eventId);
107111
$this->serverSideHelper->sendEvent($event);

app/code/Meta/Conversion/Observer/InitiateCheckout.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public function execute(Observer $observer)
7575
'content_type' => 'product',
7676
'content_ids' => $this->magentoDataHelper->getCartContentIds(),
7777
'num_items' => $this->magentoDataHelper->getCartNumItems(),
78-
'contents' => $this->magentoDataHelper->getCartContents()
78+
'contents' => $this->magentoDataHelper->getCartContents(),
79+
'custom_properties' => [
80+
'source' => $this->fbeHelper->getSource(),
81+
'pluginVersion' => $this->fbeHelper->getPluginVersion()
82+
]
7983
];
8084
$event = ServerEventFactory::createEvent('InitiateCheckout', array_filter($customData), $eventId);
8185
$this->serverSideHelper->sendEvent($event);

app/code/Meta/Conversion/Observer/Purchase.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public function execute(Observer $observer)
7575
'content_type' => 'product',
7676
'content_ids' => $this->magentoDataHelper->getOrderContentIds(),
7777
'contents' => $this->magentoDataHelper->getOrderContents(),
78-
'order_id' => (string)$this->magentoDataHelper->getOrderId()
78+
'order_id' => (string)$this->magentoDataHelper->getOrderId(),
79+
'custom_properties' => [
80+
'source' => $this->fbeHelper->getSource(),
81+
'pluginVersion' => $this->fbeHelper->getPluginVersion()
82+
]
7983
];
8084
$event = ServerEventFactory::createEvent('Purchase', array_filter($customData), $eventId);
8185
$userDataFromOrder = $this->magentoDataHelper->getUserDataFromOrder();

0 commit comments

Comments
 (0)