Implement organization-level analytics with Segment
To track analytics at the organization level, use the
group concept to map users to an Organization. When tracking events, the groupId (Organization ID) must be included in the context to ensure the event is correctly attributed to the organization.import Analytics from "analytics-node"
const orgId = '123'
// link a user to an org, and set org level traits
analytics.group({
userId,
groupId: orgId,
traits: {type: "org", orgName: 'Acme', orgStatus: 'active'},
})
// submit the actual event
analytics.track({
userId,
event: 'project-created',
properties: {userId, projectId: '123'},
// must include groupId in context or it won't work
context: {groupId: orgId},
})