@@ -11,6 +11,7 @@ import {
1111 TrialUserMetadata
1212} from '../user-data-facade.ts' ;
1313import { isAcademic } from 'educhk' ;
14+ import { generateSessionId , trackEvent } from '../metrics.ts' ;
1415
1516
1617const BearerRegex = / ^ B e a r e r ( \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