Skip to content

Commit 980582e

Browse files
committed
We've encountered a scenario where payment providers require different base currencies configured for different websites in a multisite and as a result need to send different currency in Google analytics
1 parent 04a365e commit 980582e

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

app/code/Magento/GoogleAnalytics/Block/Ga.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public function getOrdersTrackingCode()
120120
$result[] = "ga('require', 'ec', 'ec.js');";
121121

122122
foreach ($collection as $order) {
123+
$result[] = "ga('set', 'currencyCode', '" . $order->getBaseCurrencyCode() . "');";
123124
foreach ($order->getAllVisibleItems() as $item) {
124125
$result[] = sprintf(
125126
"ga('ec:addProduct', {
@@ -243,6 +244,7 @@ public function getOrdersTrackingData()
243244
'tax' => $order->getBaseTaxAmount(),
244245
'shipping' => $order->getBaseShippingAmount(),
245246
];
247+
$result['currency'] = $order->getBaseCurrencyCode();
246248
}
247249
return $result;
248250
}

app/code/Magento/GoogleAnalytics/Test/Unit/Block/GaTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public function testOrderTrackingCode()
103103
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
104104

105105
$expectedCode = "ga('require', 'ec', 'ec.js');
106+
ga('set', 'currencyCode', 'USD');
106107
ga('ec:addProduct', {
107108
'id': 'sku0',
108109
'name': 'testName0',
@@ -165,7 +166,8 @@ public function testOrderTrackingData()
165166
'price' => 0.00,
166167
'quantity' => 1
167168
]
168-
]
169+
],
170+
'currency' => 'USD'
169171
];
170172

171173
$this->gaBlock->setOrderIds([1, 2]);
@@ -213,6 +215,7 @@ protected function createOrderMock($orderItemCount = 1)
213215
$orderMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(10);
214216
$orderMock->expects($this->once())->method('getBaseTaxAmount')->willReturn(2);
215217
$orderMock->expects($this->once())->method('getBaseShippingAmount')->willReturn($orderItemCount);
218+
$orderMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('USD');
216219
return $orderMock;
217220
}
218221

app/code/Magento/GoogleAnalytics/view/frontend/web/js/google-analytics.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ define([
5757
if (config.ordersTrackingData) {
5858
ga('require', 'ec', 'ec.js');
5959

60+
ga('set', 'currencyCode', config.ordersTrackingData.currency);
61+
6062
// Collect product data for GA
6163
if (config.ordersTrackingData.products) {
6264
$.each(config.ordersTrackingData.products, function (index, value) {

0 commit comments

Comments
 (0)