Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents the functionality common to all Tracker sub-types.

Hierarchy

Index

Methods

  • Creates a child Tracker instance.

    example
    import { tracker } from '~/tracking';

    // this tracker will inherit any context data
    // set in landing's tracker while also mixing
    // in any contextual data of its own
    export const myAppTracker = tracker.child();

    myAppTracker.context({ app: 'my-app' });
    myAppTracker.event('app tracker created');

    Returns Tracker

    A new Tracker instance that will notify the same root subscriber of TrackingInfo entries, mixing in ancestor contextual data as needed.

  • context(data: Record<string, any>): void
  • Sets contextual data to be mixed into each TrackingInfo created by this Tracker or any child Trackers.

    example
    import { get } from 'lodash';
    import { store, tracker } from '~/tracking';

    store.subscribe(() => {
    const state = store.getState();
    const app = get(state, 'routes.stage');
    const drawer = get(state, 'routes.drawer');
    tracker.context({ app, drawer });
    });

    Parameters

    • data: Record<string, any>

      The data to merge into any TrackingInfo instances created by this (or child) Tracker methods.

    Returns void

  • error(err: Error): void
  • Logs an Error.

    example
    import { tracker } from '~/tracking';

    export function doSomething(param) {
    somePromiseMethod()
    .catch(errors.rethrow({ param }))
    .catch(tracker.error);
    }

    Parameters

    • err: Error

      The Error instance to log.

    Returns void

  • event(label: string, data?: Record<string, any>): void
  • Logs an event. Events usually represent important points in an application's lifecycle or user-initiated actions such as button clicks.

    NOTE: This method also creates a browser performance mark with the given message name.

    example
    import { tracker } from '~/tracking';

    window.addEventListener('click', (e) => {
    if (e.target.matches('button, a')) {
    // could grab additional contextual data
    // by looking at ancestor elements' attributes
    const type = e.target.tagName.toLowerCase();
    tracker.event('click', {
    tags: ['ui', type],
    label: e.target.innerText
    });
    }
    });

    Parameters

    • label: string

      The name of the event to log.

    • Optional data: Record<string, any>

      Optional information to associate with this TrackingInfo.

    Returns void

  • uuid(): string
  • Generates a random RFC 4122 UUID guaranteed to be unique.

    example
    import { tracker } from '~/tracking';
    import { proxy } from '~/path/to/data';

    proxy.use({
    headers: {
    'x-session-id': tracker.uuid()
    },
    match: {
    base: '^my\-app' // can use regular expression syntax
    }
    });

    Returns string