diff --git a/DataLayer/Event/PurchaseWebhookEvent.php b/DataLayer/Event/PurchaseWebhookEvent.php index a424c0e7..42e8a25b 100644 --- a/DataLayer/Event/PurchaseWebhookEvent.php +++ b/DataLayer/Event/PurchaseWebhookEvent.php @@ -102,6 +102,24 @@ public function purchase(OrderInterface $order) ] ]; + // Additional shipping, base currency and payment data used by AdPage to + // calculate the actual profit (COGS, carrier rate, payment fees) per order. + // Purely additive: existing keys keep their name, meaning and value. + try { + $data['ecommerce'] += [ + 'shipping_method' => $order->getShippingDescription() ?? '', + 'shipping_method_code' => $order->getShippingMethod() ?? '', + 'shipping_excl_tax' => $this->priceFormatter->format((float)$order->getShippingAmount()), + 'base_shipping_excl_tax' => $this->priceFormatter->format((float)$order->getBaseShippingAmount()), + 'base_value' => $this->priceFormatter->format((float)$order->getBaseGrandTotal()), + 'base_tax' => $this->priceFormatter->format((float)$order->getBaseTaxAmount()), + 'base_currency' => $order->getBaseCurrencyCode() ?? '', + 'payment_type' => $order->getPayment() ? (string)$order->getPayment()->getMethod() : '' + ]; + } catch (\Exception $e) { + $this->debugger->debug('PurchaseWebhookEvent::purchase(): could not resolve shipping/base data: ' . $e->getMessage()); + } + try { $data['user_data'] = [ "customer_id" => $order->getCustomerId() ?? '', diff --git a/composer.json b/composer.json index e0eb4be4..21b4288c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "tagginggroup/gtm", - "version": "1.6.0", + "version": "1.7.0", "license": "OSL-3.0", "type": "magento2-module", "description": "AdPage tagging integration for Magento 2",