Skip to content

Commit

Permalink
Merge pull request #57227 from nkdengineer/fix/57122
Browse files Browse the repository at this point in the history
fix: Duplicate paid adoption events are logged
  • Loading branch information
arosiclair authored Mar 4, 2025
2 parents 734bc98 + 49cd067 commit da5d0c9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/libs/actions/PaymentMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import type {
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import * as CardUtils from '@libs/CardUtils';
import GoogleTagManager from '@libs/GoogleTagManager';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import {getCardForSubscriptionBilling} from '@libs/SubscriptionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
Expand Down Expand Up @@ -272,8 +274,11 @@ function addSubscriptionPaymentCard(
failureData,
});
}

GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
if (getCardForSubscriptionBilling()) {
Log.info(`[GTM] Not logging ${CONST.ANALYTICS.EVENT.PAID_ADOPTION} because a card was already added`);
} else {
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
}
}

/**
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/GoogleTagManagerTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,30 @@ import {addPaymentCard, addSubscriptionPaymentCard} from '@libs/actions/PaymentM
import {createWorkspace} from '@libs/actions/Policy/Policy';
import GoogleTagManager from '@libs/GoogleTagManager';
import OnboardingModalNavigator from '@libs/Navigation/AppNavigator/Navigators/OnboardingModalNavigator';
import {getCardForSubscriptionBilling} from '@libs/SubscriptionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {FundList} from '@src/types/onyx';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

jest.mock('@libs/GoogleTagManager');

// Mock the Overlay since it doesn't work in tests
jest.mock('@libs/Navigation/AppNavigator/Navigators/Overlay');

const FUND_LIST: FundList = {
defaultCard: {
isDefault: true,
accountData: {
cardYear: new Date().getFullYear(),
cardMonth: new Date().getMonth() + 1,
additionalData: {
isBillingCard: true,
},
},
},
};

describe('GoogleTagManagerTest', () => {
const accountID = 123456;

Expand Down Expand Up @@ -127,4 +142,23 @@ describe('GoogleTagManagerTest', () => {
expect(GoogleTagManager.publishEvent).toBeCalledTimes(1);
expect(GoogleTagManager.publishEvent).toBeCalledWith(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
});

it('addSubscriptionPaymentCard when changing payment card, will not publish event paid_adoption', async () => {
await Onyx.multiSet({
[ONYXKEYS.FUND_LIST]: FUND_LIST,
});

addSubscriptionPaymentCard(accountID, {
cardNumber: 'cardNumber',
cardYear: 'cardYear',
cardMonth: 'cardMonth',
cardCVV: 'cardCVV',
addressName: 'addressName',
addressZip: 'addressZip',
currency: 'USD',
});

expect(!!getCardForSubscriptionBilling()).toBe(true);
expect(GoogleTagManager.publishEvent).toBeCalledTimes(0);
});
});

0 comments on commit da5d0c9

Please sign in to comment.