Skip to content

Commit ec10f7d

Browse files
committed
Log student requests by domain in Posthog
1 parent 5a27fb7 commit ec10f7d

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

api/src/functions/request-student-account.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
TrialUserMetadata
1212
} from '../user-data-facade.ts';
1313
import { isAcademic } from 'educhk';
14+
import { generateSessionId, trackEvent } from '../metrics.ts';
1415

1516

1617
const BearerRegex = /^Bearer (\S+)$/;
@@ -53,8 +54,15 @@ export const handler = catchErrors(async (event) => {
5354
const email = user.email;
5455

5556
const emailDomain = email.split('@')[1]?.toLowerCase();
57+
58+
// We track requests - but not specific users, just domains
59+
const sessionId = generateSessionId();
60+
trackEvent(sessionId, 'Student', 'request', { emailDomain });
61+
5662
if (!emailDomain || !isAcademic(emailDomain)) {
5763
log.info(`Student account rejected for non-academic email: ${email}`);
64+
65+
trackEvent(sessionId, 'Student', 'non-academic', { emailDomain });
5866
return {
5967
statusCode: 403,
6068
headers,
@@ -76,6 +84,7 @@ export const handler = catchErrors(async (event) => {
7684
existingExpiry > Date.now() + TWO_MONTHS_MS;
7785

7886
if (hasActiveStudentSub) {
87+
trackEvent(sessionId, 'Student', 'already-active', { emailDomain });
7988
return {
8089
statusCode: 409,
8190
headers,
@@ -87,6 +96,7 @@ export const handler = catchErrors(async (event) => {
8796
})
8897
};
8998
} else if (existingMeta.subscription_status === 'active') {
99+
trackEvent(sessionId, 'Student', 'paid-account', { emailDomain });
90100
return {
91101
statusCode: 409,
92102
headers,
@@ -115,6 +125,8 @@ export const handler = catchErrors(async (event) => {
115125
`, expires ${new Date(expiry).toISOString()}`
116126
);
117127

128+
trackEvent(sessionId, 'Student', 'granted', { emailDomain });
129+
118130
return {
119131
statusCode: 200,
120132
headers,

0 commit comments

Comments
 (0)