Skip to content

Commit 447d06f

Browse files
committed
use consts for event names
1 parent d4e4e90 commit 447d06f

File tree

7 files changed

+21
-10
lines changed

7 files changed

+21
-10
lines changed

Diff for: src/CONST.ts

+8
Original file line numberDiff line numberDiff line change
@@ -6202,6 +6202,14 @@ const CONST = {
62026202
HAS_VIOLATIONS: 'hasViolations',
62036203
HAS_TRANSACTION_THREAD_VIOLATIONS: 'hasTransactionThreadViolations',
62046204
},
6205+
6206+
ANALYTICS: {
6207+
EVENT: {
6208+
SIGN_UP: 'sign_up',
6209+
WORKSPACE_CREATED: 'workspace_created',
6210+
PAID_ADOPTION: 'paid_adoption',
6211+
},
6212+
},
62056213
} as const;
62066214

62076215
type Country = keyof typeof CONST.ALL_COUNTRIES;

Diff for: src/libs/GoogleTagManager/types.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import type {ValueOf} from 'type-fest';
2+
import type CONST from '@src/CONST';
3+
14
/**
25
* An event that can be published to Google Tag Manager. New events must be configured in GTM before they can be used
36
* in the app.
47
*/
5-
type GoogleTagManagerEvent = 'sign_up' | 'workspace_created' | 'paid_adoption';
8+
type GoogleTagManagerEvent = ValueOf<typeof CONST.ANALYTICS.EVENT>;
69

710
type GoogleTagManagerModule = {
811
publishEvent: (event: GoogleTagManagerEvent, accountID: number) => void;

Diff for: src/libs/Navigation/AppNavigator/Navigators/OnboardingModalNavigator.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function OnboardingModalNavigator() {
3535
return;
3636
}
3737

38-
GoogleTagManager.publishEvent('sign_up', accountID);
38+
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.SIGN_UP, accountID);
3939
}, [accountID]);
4040

4141
const handleOuterClick = useCallback(() => {

Diff for: src/libs/actions/IOU.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3477,7 +3477,7 @@ function categorizeTrackedExpense(
34773477
// If a draft policy was used, then the CategorizeTrackedExpense command will create a real one
34783478
// so let's track that conversion here
34793479
if (isDraftPolicy) {
3480-
GoogleTagManager.publishEvent('workspace_created', userAccountID);
3480+
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.WORKSPACE_CREATED, userAccountID);
34813481
}
34823482
}
34833483

Diff for: src/libs/actions/PaymentMethods.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function addPaymentCard(accountID: number, params: PaymentCardParams) {
205205
failureData,
206206
});
207207

208-
GoogleTagManager.publishEvent('paid_adoption', accountID);
208+
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
209209
}
210210

211211
/**
@@ -272,7 +272,7 @@ function addSubscriptionPaymentCard(
272272
});
273273
}
274274

275-
GoogleTagManager.publishEvent('paid_adoption', accountID);
275+
GoogleTagManager.publishEvent(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
276276
}
277277

278278
/**

Diff for: src/libs/actions/Policy/Policy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName
18411841

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

18471847
return params;

Diff for: tests/unit/GoogleTagManagerTest.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('GoogleTagManagerTest', () => {
5050

5151
// Then we publish the sign_up event only once
5252
expect(GoogleTagManager.publishEvent).toBeCalledTimes(1);
53-
expect(GoogleTagManager.publishEvent).toBeCalledWith('sign_up', accountID);
53+
expect(GoogleTagManager.publishEvent).toBeCalledWith(CONST.ANALYTICS.EVENT.SIGN_UP, accountID);
5454
});
5555

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

6464
// Then we publish a workspace_created event only once
6565
expect(GoogleTagManager.publishEvent).toBeCalledTimes(1);
66-
expect(GoogleTagManager.publishEvent).toBeCalledWith('workspace_created', accountID);
66+
expect(GoogleTagManager.publishEvent).toBeCalledWith(CONST.ANALYTICS.EVENT.WORKSPACE_CREATED, accountID);
6767
});
6868

6969
test('workspace_created - categorizeTrackedExpense', () => {
@@ -113,7 +113,7 @@ describe('GoogleTagManagerTest', () => {
113113

114114
// Then we publish a paid_adoption event only once
115115
expect(GoogleTagManager.publishEvent).toBeCalledTimes(1);
116-
expect(GoogleTagManager.publishEvent).toBeCalledWith('paid_adoption', accountID);
116+
expect(GoogleTagManager.publishEvent).toBeCalledWith(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
117117
});
118118

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

131131
// Then we publish a paid_adoption event only once
132132
expect(GoogleTagManager.publishEvent).toBeCalledTimes(1);
133-
expect(GoogleTagManager.publishEvent).toBeCalledWith('paid_adoption', accountID);
133+
expect(GoogleTagManager.publishEvent).toBeCalledWith(CONST.ANALYTICS.EVENT.PAID_ADOPTION, accountID);
134134
});
135135
});

0 commit comments

Comments
 (0)