Spectacle JS

Group

Associating users with groups in Spectacle

The group function in Spectacle allows you to associate a user with a specific group, such as a company, organization or account.

Understanding group tracking

Group calls help you analyze user data in the context of their organization. There are two important IDs in a Group call:

  • groupId: identifies the specific group or organization
  • userId (or anonymousId): identifies the individual user

A user can belong to multiple groups (with different groupId values), but they'll have a single userId across all these groups.

spectacle.group(groupId, [traits]);

Parameters

  • groupId (String, required): A unique identifier for the group in your database
  • traits (Object, optional): Properties that describe the group, such as name, industry, or plan

Example usage

Basic group call associating the current user with a group:

spectacle.group('company_123', {
  name: 'Acme Inc.',
  plan: 'enterprise'
});

Special properties for group

Spectacle recognizes certain special properties in the group traits:

TraitTypeDescription
nameStringThe name of the group/company
emailStringAn email address for the group
planStringThe subscription plan of the group

You can also include any custom properties that are relevant to your business:

spectacle.group('company_123', {
  name: 'Acme Inc.',
  industry: 'Technology',
  employees: 329,
  plan: 'enterprise',
  annualRevenue: '5000000',
  region: 'EMEA',
  customerSince: '2022-01-15'
});

When to use group

Group calls are most valuable in these scenarios:

  1. When onboarding a new user who belongs to an organization
  2. When a user's group membership changes
  3. When a group's properties change (e.g., upgrading to a new plan)

Combining group tracking with identify calls can link customer journeys for several users together.

Previous
track()