MSDN Documentation

Analytics - Data Collection

Understanding Data Collection

This section details how your application collects data for analytics purposes. Effective data collection is crucial for gaining insights into user behavior, application performance, and identifying areas for improvement.

Methods of Data Collection

We support several methods for collecting data, allowing you to choose the most suitable approach for your needs:

1. Event Tracking

Event tracking allows you to record specific user interactions within your application. These events can be anything from button clicks, form submissions, page views, to custom actions.

Key Features:

  • Capture event name, category, label, and value.
  • Track user engagement and feature usage.
  • Define custom events relevant to your business logic.
Example: Tracking a Button Click

// JavaScript Example
analytics.track('button_click', {
    category: 'User Interface',
    label: 'Submit Button',
    value: 1
});
                

2. User Identification

Identifying users allows you to track their journey across different sessions and devices, providing a more comprehensive view of their behavior.

Key Features:

  • Assign unique identifiers to users (anonymous or logged-in).
  • Set user properties to segment and analyze user groups.
  • Merge data from different sessions under a single user ID.
Example: Identifying a User

// JavaScript Example
analytics.identify('user_12345', {
    email: 'user@example.com',
    plan: 'Premium',
    signup_date: '2023-10-27T10:00:00Z'
});
                

3. Page View Tracking

Automatically track every page or screen viewed by your users. This is fundamental for understanding content consumption and navigation patterns.

Key Features:

  • Automatic capture of page URL and title.
  • Option to track custom page names.
  • Integration with route changes in Single Page Applications (SPAs).
Example: Manual Page View Tracking (for SPAs)

// JavaScript Example
analytics.page('/dashboard/overview', {
    title: 'Dashboard Overview'
});
                

Data Collection API Reference

Below is a summary of the core data collection methods available:

analytics.track(eventName, properties)

Records an event with associated properties.

Parameters:
Name Type Description Required
eventName String The name of the event to track. Yes
properties Object A JSON object containing key-value pairs describing the event. No

analytics.identify(userId, traits)

Identifies a user and sets their traits.

Parameters:
Name Type Description Required
userId String A unique identifier for the user. Yes
traits Object A JSON object containing key-value pairs describing the user (e.g., email, name, plan). No

analytics.page(path, properties)

Records a page view.

Parameters:
Name Type Description Required
path String The URL path or name of the page being viewed. Yes
properties Object A JSON object containing additional page-specific properties. No

Best Practices