Integrates the Segment Node.js SDK (@segment/analytics-node) into the TeachLink backend to provide unified analytics event tracking, user identification, and destination configuration management.
| File | Description |
|---|---|
src/analytics/segment/segment.service.ts |
Core service — wraps Segment SDK, exposes track() and identify(), flushes on graceful shutdown |
src/analytics/segment/segment-destination-config.entity.ts |
TypeORM entity persisting destination name, enabled flag, and JSON settings |
src/analytics/segment/segment.dto.ts |
Validated DTOs: TrackEventDto, IdentifyUserDto, CreateDestinationConfigDto, UpdateDestinationConfigDto |
src/analytics/segment/segment.controller.ts |
REST controller for event tracking and destination config CRUD |
src/analytics/segment/segment.module.ts |
NestJS module wiring the above together |
src/analytics/segment/segment.service.spec.ts |
Unit tests (8 passing) |
| File | Change |
|---|---|
src/analytics/analytics.module.ts |
Imports and exports SegmentModule |
src/config/env.validation.ts |
Adds optional SEGMENT_WRITE_KEY env var |
package.json / package-lock.json |
Adds @segment/analytics-node@2.1.2 |
| Method | Path | Description |
|---|---|---|
POST |
/analytics/segment/track |
Track an analytics event |
POST |
/analytics/segment/identify |
Identify a user with traits |
POST |
/analytics/segment/destinations |
Create a destination configuration |
GET |
/analytics/segment/destinations |
List all destination configurations |
GET |
/analytics/segment/destinations/:id |
Get a destination configuration |
PATCH |
/analytics/segment/destinations/:id |
Update a destination configuration |
DELETE |
/analytics/segment/destinations/:id |
Delete a destination configuration |
Add to .env:
SEGMENT_WRITE_KEY=your_segment_write_keySEGMENT_WRITE_KEY is optional. When absent, the service logs a warning and all calls are no-ops — the app boots normally without Segment configured.
- 8 unit tests covering:
track,identify,anonymousIdforwarding, graceful flush on shutdown, and no-op behaviour when write key is absent. - TypeScript type-check passes for all new files.
- Segment SDK integration
- Event tracking to Segment
- User identification
- Destination configuration UI (REST API) closes #596