Skip to content

Commit

Permalink
use consts for event names
Browse files Browse the repository at this point in the history
  • Loading branch information
arosiclair committed Nov 7, 2024
1 parent d4e4e90 commit 447d06f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6202,6 +6202,14 @@ const CONST = {
HAS_VIOLATIONS: 'hasViolations',
HAS_TRANSACTION_THREAD_VIOLATIONS: 'hasTransactionThreadViolations',
},

ANALYTICS: {
EVENT: {
SIGN_UP: 'sign_up',
WORKSPACE_CREATED: 'workspace_created',
PAID_ADOPTION: 'paid_adoption',
},
},
} as const;

type Country = keyof typeof CONST.ALL_COUNTRIES;
Expand Down
5 changes: 4 additions & 1 deletion src/libs/GoogleTagManager/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';

/**
* An event that can be published to Google Tag Manager. New events must be configured in GTM before they can be used
* in the app.
*/
type GoogleTagManagerEvent = 'sign_up' | 'workspace_created' | 'paid_adoption';
type GoogleTagManagerEvent = ValueOf<typeof CONST.ANALYTICS.EVENT>;

type GoogleTagManagerModule = {
publishEvent: (event: GoogleTagManagerEvent, accountID: number) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function OnboardingModalNavigator() {
return;
}

GoogleTagManager.publishEvent('sign_up', accountID);
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.SIGN_UP, accountID);
}, [accountID]);

const handleOuterClick = useCallback(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3477,7 +3477,7 @@ function categorizeTrackedExpense(
// If a draft policy was used, then the CategorizeTrackedExpense command will create a real one
// so let's track that conversion here
if (isDraftPolicy) {
GoogleTagManager.publishEvent('workspace_created', userAccountID);
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.WORKSPACE_CREATED, userAccountID);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/PaymentMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function addPaymentCard(accountID: number, params: PaymentCardParams) {
failureData,
});

GoogleTagManager.publishEvent('paid_adoption', accountID);
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
}

/**
Expand Down Expand Up @@ -272,7 +272,7 @@ function addSubscriptionPaymentCard(
});
}

GoogleTagManager.publishEvent('paid_adoption', accountID);
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName

// Publish a workspace created event if this is their first policy
if (getAdminPolicies().length === 0) {
GoogleTagManager.publishEvent('workspace_created', sessionAccountID);
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.WORKSPACE_CREATED, sessionAccountID);
}

return params;
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/GoogleTagManagerTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('GoogleTagManagerTest', () => {

// Then we publish the sign_up event only once
expect(GoogleTagManager.publishEvent).toBeCalledTimes(1);
expect(GoogleTagManager.publishEvent).toBeCalledWith('sign_up', accountID);
expect(GoogleTagManager.publishEvent).toBeCalledWith(CONST.ANALYTICS.EVENT.SIGN_UP, accountID);
});

test('workspace_created', async () => {
Expand All @@ -63,7 +63,7 @@ describe('GoogleTagManagerTest', () => {

// Then we publish a workspace_created event only once
expect(GoogleTagManager.publishEvent).toBeCalledTimes(1);
expect(GoogleTagManager.publishEvent).toBeCalledWith('workspace_created', accountID);
expect(GoogleTagManager.publishEvent).toBeCalledWith(CONST.ANALYTICS.EVENT.WORKSPACE_CREATED, accountID);
});

test('workspace_created - categorizeTrackedExpense', () => {
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('GoogleTagManagerTest', () => {

// Then we publish a paid_adoption event only once
expect(GoogleTagManager.publishEvent).toBeCalledTimes(1);
expect(GoogleTagManager.publishEvent).toBeCalledWith('paid_adoption', accountID);
expect(GoogleTagManager.publishEvent).toBeCalledWith(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
});

test('paid_adoption - addSubscriptionPaymentCard', () => {
Expand All @@ -130,6 +130,6 @@ describe('GoogleTagManagerTest', () => {

// Then we publish a paid_adoption event only once
expect(GoogleTagManager.publishEvent).toBeCalledTimes(1);
expect(GoogleTagManager.publishEvent).toBeCalledWith('paid_adoption', accountID);
expect(GoogleTagManager.publishEvent).toBeCalledWith(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
});
});

0 comments on commit 447d06f

Please sign in to comment.