Commit 41c263b3 authored by Simon Knox's avatar Simon Knox

Merge branch 'fix/gtm-enhanced-ecommerce-currency-code' into 'master'

Fix currencyCode in enhanced ecommerce events

See merge request gitlab-org/gitlab!79878
parents cd4260c0 102f7f09
...@@ -55,16 +55,15 @@ const pushEvent = (event, args = {}) => { ...@@ -55,16 +55,15 @@ const pushEvent = (event, args = {}) => {
} }
}; };
const pushEnhancedEcommerceEvent = (event, currencyCode, args = {}) => { const pushEnhancedEcommerceEvent = (event, args = {}) => {
if (!window.dataLayer) { if (!window.dataLayer) {
return; return;
} }
try { try {
window.dataLayer.push({ ecommerce: null }); window.dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object
window.dataLayer.push({ window.dataLayer.push({
event, event,
currencyCode,
...args, ...args,
}); });
} catch (e) { } catch (e) {
...@@ -189,6 +188,7 @@ export const trackCheckout = (selectedPlan, quantity) => { ...@@ -189,6 +188,7 @@ export const trackCheckout = (selectedPlan, quantity) => {
const eventData = { const eventData = {
ecommerce: { ecommerce: {
currencyCode: 'USD',
checkout: { checkout: {
actionField: { step: 1 }, actionField: { step: 1 },
products: [product], products: [product],
...@@ -197,7 +197,7 @@ export const trackCheckout = (selectedPlan, quantity) => { ...@@ -197,7 +197,7 @@ export const trackCheckout = (selectedPlan, quantity) => {
}; };
// eslint-disable-next-line @gitlab/require-i18n-strings // eslint-disable-next-line @gitlab/require-i18n-strings
pushEnhancedEcommerceEvent('EECCheckout', 'USD', eventData); pushEnhancedEcommerceEvent('EECCheckout', eventData);
}; };
export const trackTransaction = (transactionDetails) => { export const trackTransaction = (transactionDetails) => {
...@@ -215,6 +215,7 @@ export const trackTransaction = (transactionDetails) => { ...@@ -215,6 +215,7 @@ export const trackTransaction = (transactionDetails) => {
const eventData = { const eventData = {
ecommerce: { ecommerce: {
currencyCode: 'USD',
purchase: { purchase: {
actionField: { actionField: {
id: transactionId, id: transactionId,
...@@ -228,5 +229,5 @@ export const trackTransaction = (transactionDetails) => { ...@@ -228,5 +229,5 @@ export const trackTransaction = (transactionDetails) => {
}, },
}; };
pushEnhancedEcommerceEvent('EECtransactionSuccess', 'USD', eventData); pushEnhancedEcommerceEvent('EECtransactionSuccess', eventData);
}; };
...@@ -224,8 +224,8 @@ describe('~/google_tag_manager/index', () => { ...@@ -224,8 +224,8 @@ describe('~/google_tag_manager/index', () => {
{ ecommerce: null }, { ecommerce: null },
{ {
event: 'EECCheckout', event: 'EECCheckout',
currencyCode: 'USD',
ecommerce: { ecommerce: {
currencyCode: 'USD',
checkout: { checkout: {
actionField: { step: 1 }, actionField: { step: 1 },
products: [ products: [
...@@ -254,8 +254,8 @@ describe('~/google_tag_manager/index', () => { ...@@ -254,8 +254,8 @@ describe('~/google_tag_manager/index', () => {
expect(spy).toHaveBeenCalledWith({ ecommerce: null }); expect(spy).toHaveBeenCalledWith({ ecommerce: null });
expect(spy).toHaveBeenCalledWith({ expect(spy).toHaveBeenCalledWith({
event: 'EECCheckout', event: 'EECCheckout',
currencyCode: 'USD',
ecommerce: { ecommerce: {
currencyCode: 'USD',
checkout: { checkout: {
actionField: { step: 1 }, actionField: { step: 1 },
products: [ products: [
...@@ -291,8 +291,8 @@ describe('~/google_tag_manager/index', () => { ...@@ -291,8 +291,8 @@ describe('~/google_tag_manager/index', () => {
expect(spy).toHaveBeenCalledWith({ ecommerce: null }); expect(spy).toHaveBeenCalledWith({ ecommerce: null });
expect(spy).toHaveBeenCalledWith({ expect(spy).toHaveBeenCalledWith({
event: 'EECCheckout', event: 'EECCheckout',
currencyCode: 'USD',
ecommerce: { ecommerce: {
currencyCode: 'USD',
checkout: { checkout: {
actionField: { step: 1 }, actionField: { step: 1 },
products: [ products: [
...@@ -347,8 +347,8 @@ describe('~/google_tag_manager/index', () => { ...@@ -347,8 +347,8 @@ describe('~/google_tag_manager/index', () => {
{ ecommerce: null }, { ecommerce: null },
{ {
event: 'EECtransactionSuccess', event: 'EECtransactionSuccess',
currencyCode: 'USD',
ecommerce: { ecommerce: {
currencyCode: 'USD',
purchase: { purchase: {
actionField: { actionField: {
id: '123', id: '123',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment