Skip to content

Commit 4a7a196

Browse files
author
Llorenç
committed
Format
1 parent be064c8 commit 4a7a196

2 files changed

Lines changed: 49 additions & 22 deletions

File tree

src/frontend/src/utils/analytics/Funnel.test.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("Funnel", () => {
5757
document.dispatchEvent(new Event("visibilitychange"));
5858
expect(analytics.event).toHaveBeenCalledWith(
5959
"start-login-window-session-enter",
60-
undefined
60+
undefined,
6161
);
6262
});
6363

@@ -68,7 +68,7 @@ describe("Funnel", () => {
6868
document.dispatchEvent(new Event("visibilitychange"));
6969
expect(analytics.event).toHaveBeenCalledWith(
7070
"start-login-window-session-enter",
71-
properties
71+
properties,
7272
);
7373
});
7474

@@ -78,7 +78,7 @@ describe("Funnel", () => {
7878
document.dispatchEvent(new Event("visibilitychange"));
7979
expect(analytics.event).toHaveBeenCalledWith(
8080
"start-login-window-session-leave",
81-
undefined
81+
undefined,
8282
);
8383
});
8484

@@ -89,15 +89,15 @@ describe("Funnel", () => {
8989
document.dispatchEvent(new Event("visibilitychange"));
9090
expect(analytics.event).toHaveBeenCalledWith(
9191
"start-login-window-session-leave",
92-
properties
92+
properties,
9393
);
9494
});
9595

9696
it("trigger() - tracks new registration start event", () => {
9797
funnel.trigger(LoginEvents.NewRegistrationStart);
9898
expect(analytics.event).toHaveBeenCalledWith(
9999
"login-new-registration-start",
100-
undefined
100+
undefined,
101101
);
102102
});
103103

@@ -107,7 +107,7 @@ describe("Funnel", () => {
107107
funnel.trigger(LoginEvents.NewRegistrationStart);
108108
expect(analytics.event).toHaveBeenCalledWith(
109109
"login-new-registration-start",
110-
properties
110+
properties,
111111
);
112112
});
113113

@@ -116,55 +116,70 @@ describe("Funnel", () => {
116116
funnel.trigger(LoginEvents.NewRegistrationStart, additionalProps);
117117
expect(analytics.event).toHaveBeenCalledWith(
118118
"login-new-registration-start",
119-
additionalProps
119+
additionalProps,
120120
);
121121
});
122122

123123
it("trigger() - merges init properties with additional properties", () => {
124124
const initProps = { userId: "123", source: "test" };
125125
const additionalProps = { step: 1, method: "email" };
126126
const expectedProps = { ...initProps, ...additionalProps };
127-
127+
128128
funnel.init(initProps);
129129
funnel.trigger(LoginEvents.NewRegistrationStart, additionalProps);
130-
130+
131131
expect(analytics.event).toHaveBeenCalledWith(
132132
"login-new-registration-start",
133-
expectedProps
133+
expectedProps,
134134
);
135135
});
136136

137137
it("trigger() - tracks complete passkey login flow", () => {
138138
funnel.trigger(LoginEvents.ExistingUserStart);
139-
expect(analytics.event).toHaveBeenCalledWith("login-existing-user-start", undefined);
139+
expect(analytics.event).toHaveBeenCalledWith(
140+
"login-existing-user-start",
141+
undefined,
142+
);
140143

141144
funnel.trigger(LoginEvents.ExistingUserPasskey);
142-
expect(analytics.event).toHaveBeenCalledWith("login-existing-user-passkey", undefined);
145+
expect(analytics.event).toHaveBeenCalledWith(
146+
"login-existing-user-passkey",
147+
undefined,
148+
);
143149

144150
funnel.trigger(LoginEvents.ExistingUserPasskeySuccess);
145151
expect(analytics.event).toHaveBeenCalledWith(
146152
"login-existing-user-passkey-success",
147-
undefined
153+
undefined,
148154
);
149155
});
150156

151157
it("trigger() - tracks complete OpenID login flow", () => {
152158
funnel.trigger(LoginEvents.ExistingUserStart);
153-
expect(analytics.event).toHaveBeenCalledWith("login-existing-user-start", undefined);
159+
expect(analytics.event).toHaveBeenCalledWith(
160+
"login-existing-user-start",
161+
undefined,
162+
);
154163

155164
funnel.trigger(LoginEvents.ExistingUserOpenId);
156-
expect(analytics.event).toHaveBeenCalledWith("login-existing-user-openid", undefined);
165+
expect(analytics.event).toHaveBeenCalledWith(
166+
"login-existing-user-openid",
167+
undefined,
168+
);
157169

158170
funnel.trigger(LoginEvents.ExistingUserOpenIdSuccess);
159171
expect(analytics.event).toHaveBeenCalledWith(
160172
"login-existing-user-openid-success",
161-
undefined
173+
undefined,
162174
);
163175
});
164176

165177
it("trigger() - tracks recovery start event", () => {
166178
funnel.trigger(LoginEvents.RecoveryStart);
167-
expect(analytics.event).toHaveBeenCalledWith("login-recovery-start", undefined);
179+
expect(analytics.event).toHaveBeenCalledWith(
180+
"login-recovery-start",
181+
undefined,
182+
);
168183
});
169184

170185
it("close() - stops tracking window session events", () => {

src/frontend/src/utils/analytics/Funnel.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ export class Funnel<T extends Record<string, string>> {
1919
// Start window session tracking
2020
this.#cleanupSession = trackWindowSession({
2121
onEnterSession: () => {
22-
analytics.event(`start-${this.#name}-window-session-enter`, this.#properties);
22+
analytics.event(
23+
`start-${this.#name}-window-session-enter`,
24+
this.#properties,
25+
);
2326
},
2427
onLeaveSession: () => {
25-
analytics.event(`start-${this.#name}-window-session-leave`, this.#properties);
28+
analytics.event(
29+
`start-${this.#name}-window-session-leave`,
30+
this.#properties,
31+
);
2632
},
2733
});
2834
}
@@ -50,12 +56,18 @@ export class Funnel<T extends Record<string, string>> {
5056
}
5157
}
5258

53-
trigger(event: T[keyof T], additionalProperties?: Record<string, string | number>): void {
59+
trigger(
60+
event: T[keyof T],
61+
additionalProperties?: Record<string, string | number>,
62+
): void {
5463
const eventProperties = {
5564
...(this.#properties || {}),
5665
...(additionalProperties || {}),
5766
};
58-
59-
analytics.event(event, Object.keys(eventProperties).length > 0 ? eventProperties : undefined);
67+
68+
analytics.event(
69+
event,
70+
Object.keys(eventProperties).length > 0 ? eventProperties : undefined,
71+
);
6072
}
6173
}

0 commit comments

Comments
 (0)