Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

Commit e610f7e

Browse files
author
gduval91
authored
Add currency to ecommerce
See https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#multicurrency, you can specify multiple currency in a transaction and item.
1 parent 974b786 commit e610f7e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function trackEvent($category, $action, $label = null, $value = null)
212212
*
213213
* @return AnalyticsProviderInterface
214214
*/
215-
public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null)
215+
public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null, $currency = null)
216216
{
217217
// Call to enable ecommerce tracking automatically
218218
$this->enableEcommerceTracking();
@@ -235,6 +235,10 @@ public function ecommerceAddTransaction($id, $affiliation = null, $revenue = nul
235235
$parameters['tax'] = $tax;
236236
}
237237

238+
if (!is_null($currency)) {
239+
$parameters['currency'] = $currency;
240+
}
241+
238242
$jsonParameters = json_encode($parameters);
239243
$trackingCode = "ga('ecommerce:addTransaction', {$jsonParameters});";
240244

@@ -255,7 +259,7 @@ public function ecommerceAddTransaction($id, $affiliation = null, $revenue = nul
255259
*
256260
* @return AnalyticsProviderInterface
257261
*/
258-
public function ecommerceAddItem($id, $name, $sku = null, $category = null, $price = null, $quantity = null)
262+
public function ecommerceAddItem($id, $name, $sku = null, $category = null, $price = null, $quantity = null, $currency = null)
259263
{
260264
// Call to enable ecommerce tracking automatically
261265
$this->enableEcommerceTracking();
@@ -281,6 +285,10 @@ public function ecommerceAddItem($id, $name, $sku = null, $category = null, $pri
281285
$parameters['quantity'] = $quantity;
282286
}
283287

288+
if (!is_null($currency)) {
289+
$parameters['currency'] = $currency;
290+
}
291+
284292
$jsonParameters = json_encode($parameters);
285293
$trackingCode = "ga('ecommerce:addItem', {$jsonParameters});";
286294

0 commit comments

Comments
 (0)