samhub.js
    Preparing search index...

    Class Tracker

    The Tracker class is responsible for tracking events and sending them to a specified API endpoint. It provides functionality to automatically track user IDs, referrers, and URLs, as well as to set default values for event data.

    This class is designed to be used in web applications where event tracking is required. It supports configuration options for customizing the tracking behavior.

    const tracker = new Tracker('container-id', {
    api_url: 'https://api.example.com',
    auto_track_user_id: 'localstorage',
    auto_track_referrer: true,
    auto_track_url: true,
    debug: console.log
    });

    tracker.track('page_view', { utm_source: 'value' });
    Index

    Constructors

    Properties

    Methods

    Constructors

    • Initializes a new instance of the Tracker class.

      Parameters

      • containerId: string

        The ID of the container to associate with the tracker.

      • options: TrackerOptions = {}

        Optional configuration for the tracker. Defaults to:

        • api_url: The API URL to use.
        • auto_track_user_id: Specifies how to track the user ID (default is 'cookie').
        • auto_track_session: Whether to automatically track the session ID (default is true).
        • auto_track_referrer: Whether to automatically track the referrer (default is true).
        • auto_track_url: Whether to automatically track the URL (default is true).

      Returns Tracker

    Properties

    containerId: string
    options: TrackerOptions

    Methods

    • Tracks an event by sending the event data to the specified API endpoint.

      Parameters

      • eventName: string

        The name of the event to be tracked.

      • eventData: EventData

        An object containing the data associated with the event.

        The method performs the following steps:

        1. Clones the provided eventData object to avoid mutating the original data.
        2. Sets default values for the event data using setEventDefaults.
        3. Logs debug information if debugging is enabled.
        4. Creates a new Pixel instance with the API URL, container ID, and debug options.
        5. Sends the event data using the Pixel instance.

      Returns void