Prompt
I’m building a B2B SaaS and need to track user behavior across accounts
Latest observation
To track user behavior across accounts in a B2B SaaS, you’ll want an analytics model that separates person, workspace/account, and event cleanly.
Core concept
In B2B SaaS, the same user can:
- belong to multiple accounts/workspaces
- switch between them
- have different roles/permissions per account
So your tracking should support:
- User-level identity: who the person is
- Account-level identity: which tenant/workspace/org they acted within
- Event-level context: what they did, when, and in which account
Recommended data model
1. User
Represents the individual human.
Fields:
user_idemailnamecreated_at
2. Account / Workspace / Org
Represents the customer tenant.
Fields:
account_idnameplancreated_at
3. Membership
Join table for user ↔ account relationships.
Fields:
user_idaccount_idrolejoined_atstatus
This is important because one user may belong to many accounts.
4. Events
Each behavior event should include both IDs when relevant.
Example fields:
event_iduser_idaccount_idevent_nametimestampproperties
Example:
{
"event_name": "created_report",
"user_id": "u_123",
"account_id": "a_456",
"timestamp": "2026-10-23T12:34:56Z",
"properties": {
"report_type": "sales",
"source": "dashboard"
}
}
What to track
Identity events
Track when:
- user signs up
- logs in
- joins an account
- switches account
- updates profile
- changes role
Product events
Track actions like:
- created project
- invited teammate
- exported data
- viewed dashboard
- connected integration
- upgraded plan
Account events
Track tenant-level actions:
- billing updated
- plan changed
- workspace created
- seat added/removed
- subscription canceled
Best practices
1. Always include account_id
Even if you can infer it from session state, store it explicitly in event payloads. This makes analysis much easier.
2. Use stable internal IDs
Don’t rely on email as your primary identifier. Emails change; IDs should not.
3. Handle users in multiple accounts
Your analytics should support:
- activity per user across all accounts
- activity per account
- activity per user within a specific account
4. Separate user identity from session identity
A session may begin unauthenticated and later become identified. Make sure you can link anonymous activity to the user after login if needed.
5. Capture role and plan context
For B2B SaaS, behavior often differs by:
- admin vs member
- free vs paid
- trial vs active subscription
Add these as event/user/account properties or derive them at query time.
Example tracking flow
- User signs up
- create
user
- create
- User creates a new workspace
- create
account - create
membership
- create
- User performs actions in that workspace
- send events with both
user_idandaccount_id
- send events with both
- User joins a second workspace
- add another
membership
- add another
- User switches workspace
- future events use new
account_id
- future events use new
If you use a product analytics tool
Tools like PostHog, Amplitude, Segment, Mixpanel, RudderStack, or Snowplow can support this model.
Typical implementation:
- set
user_idwhen authenticated - set
group_id/account_idfor workspace context - attach account traits like
plan,industry,seat_count
For example, in Segment-style tracking:
identify(user_id, traits)group(account_id, traits)track(event_name, properties)
Important compliance note
If you’re tracking behavior across accounts:
- be transparent in your privacy policy
- avoid collecting unnecessary PII
- ensure consent/DSAR support if you operate under GDPR/CCPA
- be careful with cross-tenant access and reporting
A good default schema
If you want a simple, scalable setup, use:
usersaccountsmembershipsevents
with every event containing:
user_idaccount_idevent_nametimestampproperties
If you want, I can also help you design:
- a database schema for this,
- a tracking plan of events to instrument, or
- example code for Segment/PostHog/Amplitude.