Skip to content

Commit 7a24d2a

Browse files
feat(analytics): identify + groupIdentify on auth/org events (#3306)
* feat(analytics): identify + groupIdentify on auth/org events Add analytics tracking calls to auth and organization flows: - identify on signup (email, name, provider) and signin (email, name, lastLoginAt) - groupIdentify on org create (name, createdAt) and org update (name) - groupIdentify on billing plan.changed event (plan) All calls are wrapped in try/catch to never break the main flow. Closes #3296 * fix(analytics): await async init and mock middleware in identify tests
1 parent 723ba4a commit 7a24d2a

4 files changed

Lines changed: 552 additions & 0 deletions

File tree

modules/analytics/analytics.init.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import AnalyticsService from './services/analytics.service.js';
55
import analyticsMiddleware from './middlewares/analytics.middleware.js';
6+
import billingEvents from '../billing/lib/events.js';
67

78
/**
89
* Initialise the analytics module.
@@ -14,10 +15,19 @@ import analyticsMiddleware from './middlewares/analytics.middleware.js';
1415
* lazily inside the `res.on('finish')` handler, so it is safe to mount
1516
* here — before route-level auth middleware is wired.
1617
*
18+
* Listens for billing plan changes to update group properties.
19+
*
1720
* @param {object} app - Express application instance
1821
* @returns {Promise<void>}
1922
*/
2023
export default async (app) => {
2124
await AnalyticsService.init();
2225
app.use(analyticsMiddleware);
26+
27+
// Listen for billing plan changes and update group properties
28+
billingEvents.on('plan.changed', ({ organizationId, newPlan }) => {
29+
try {
30+
AnalyticsService.groupIdentify('company', String(organizationId), { plan: newPlan });
31+
} catch (_) { /* analytics must not break billing flow */ }
32+
});
2333
};

0 commit comments

Comments
 (0)