Segment.js Event Types

Segment.js is a part of Segment’s suite of tools for collecting and routing customer data. When you use Segment (specifically the Segment JavaScript library), you can track different types of events, each with its own specific structure and purpose. Here are the key event types supported by Segment along with example payloads:

1. Identify

  • Purpose: To tie a user to their actions and record traits about them.
  • Payload Example:
  analytics.identify('userId123', {
    email: 'john.doe@example.com',
    name: 'John Doe'
  });

2. Track

  • Purpose: To track any action that a user performs along with any properties that describe the action.
  • Payload Example:
  analytics.track('Item Purchased', {
    item: 'Blue T-shirt',
    size: 'Medium',
    price: 29.95
  });

3. Page

  • Purpose: To record page views on your website, along with optional extra information about the page being viewed.
  • Payload Example:
  analytics.page('Home', {
    title: 'Homepage',
    url: 'https://www.example.com'
  });

4. Group

  • Purpose: To associate an individual user with a group, such as a company, organization, account, or project.
  • Payload Example:
  analytics.group('groupId123', {
    name: 'Company Inc.',
    industry: 'Technology',
    employees: 500
  });

5. Alias

  • Purpose: To merge two user identities, effectively connecting two sets of user data as one.
  • Payload Example:
  analytics.alias('newUserId');

6. Screen (for mobile)

  • Purpose: Similar to the page method but used in a mobile context to record views of different screens in your mobile app.
  • Payload Example:
  // This is more relevant for mobile SDKs like iOS or Android
  analytics.screen('Dashboard', {
    title: 'Dashboard Screen',
    category: 'App Navigation'
  });

Each of these event types allows you to send additional data that can be customized based on your application’s needs. The payload examples provided here are basic and can be expanded with more properties relevant to your specific use case.

Remember to follow best practices for data collection and privacy, ensuring that you have consent where necessary and that you’re only collecting data that is essential for your purposes. Segment also provides settings and tools to help manage data privacy and compliance.

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to content