Skip to content

Commit cf6d0b9

Browse files
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
1 parent 7e60bbb commit cf6d0b9

4 files changed

Lines changed: 547 additions & 0 deletions

File tree

modules/analytics/analytics.init.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22
* Module dependencies
33
*/
44
import AnalyticsService from './services/analytics.service.js';
5+
import billingEvents from '../billing/lib/events.js';
56

67
/**
78
* Initialise the analytics module.
89
* Called automatically by the Express init loop (matched via the
910
* `modules/{name}/{name}.init.js` glob in config/assets.js).
11+
* Listens for billing plan changes to update group properties.
1012
* @param {object} _app - Express application instance (unused)
1113
* @returns {Promise<void>}
1214
*/
1315
// eslint-disable-next-line no-unused-vars
1416
export default async (_app) => {
1517
await AnalyticsService.init();
18+
19+
// Listen for billing plan changes and update group properties
20+
billingEvents.on('plan.changed', ({ organizationId, newPlan }) => {
21+
try {
22+
AnalyticsService.groupIdentify('company', String(organizationId), { plan: newPlan });
23+
} catch (_) { /* analytics must not break billing flow */ }
24+
});
1625
};

0 commit comments

Comments
 (0)