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 = {}) => {
}
};
const pushEnhancedEcommerceEvent = (event, currencyCode, args = {}) => {
const pushEnhancedEcommerceEvent = (event, args = {}) => {
if (!window.dataLayer) {
return;
}
try {
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object
window.dataLayer.push({
event,
currencyCode,
...args,
});
} catch (e) {
......@@ -189,6 +188,7 @@ export const trackCheckout = (selectedPlan, quantity) => {
const eventData = {
ecommerce: {
currencyCode: 'USD',
checkout: {
actionField: { step: 1 },
products: [product],
......@@ -197,7 +197,7 @@ export const trackCheckout = (selectedPlan, quantity) => {
};
// eslint-disable-next-line @gitlab/require-i18n-strings
pushEnhancedEcommerceEvent('EECCheckout', 'USD', eventData);
pushEnhancedEcommerceEvent('EECCheckout', eventData);
};
export const trackTransaction = (transactionDetails) => {
......@@ -215,6 +215,7 @@ export const trackTransaction = (transactionDetails) => {
const eventData = {
ecommerce: {
currencyCode: 'USD',
purchase: {
actionField: {
id: transactionId,
......@@ -228,5 +229,5 @@ export const trackTransaction = (transactionDetails) => {
},
};
pushEnhancedEcommerceEvent('EECtransactionSuccess', 'USD', eventData);
pushEnhancedEcommerceEvent('EECtransactionSuccess', eventData);
};
......@@ -224,8 +224,8 @@ describe('~/google_tag_manager/index', () => {
{ ecommerce: null },
{
event: 'EECCheckout',
currencyCode: 'USD',
ecommerce: {
currencyCode: 'USD',
checkout: {
actionField: { step: 1 },
products: [
......@@ -254,8 +254,8 @@ describe('~/google_tag_manager/index', () => {
expect(spy).toHaveBeenCalledWith({ ecommerce: null });
expect(spy).toHaveBeenCalledWith({
event: 'EECCheckout',
currencyCode: 'USD',
ecommerce: {
currencyCode: 'USD',
checkout: {
actionField: { step: 1 },
products: [
......@@ -291,8 +291,8 @@ describe('~/google_tag_manager/index', () => {
expect(spy).toHaveBeenCalledWith({ ecommerce: null });
expect(spy).toHaveBeenCalledWith({
event: 'EECCheckout',
currencyCode: 'USD',
ecommerce: {
currencyCode: 'USD',
checkout: {
actionField: { step: 1 },
products: [
......@@ -347,8 +347,8 @@ describe('~/google_tag_manager/index', () => {
{ ecommerce: null },
{
event: 'EECtransactionSuccess',
currencyCode: 'USD',
ecommerce: {
currencyCode: 'USD',
purchase: {
actionField: {
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