Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @amplitude/analytics-browser

Index

Functions

  • Adds a new plugin.

    const plugin = {
    name: 'myPlugin',
    type: PluginType.ENRICHMENT,
    setup(config: Config) {
    return;
    },
    execute(context: Event) {
    return context;
    },
    };
    amplitude.add(plugin);

    Parameters

    Returns Types.AmplitudeReturn<void>

  • Flush all unsent events.

    flush();
    

    Returns Types.AmplitudeReturn<void>

  • getDeviceId(): undefined | string
  • Returns current device ID.

    const deviceId = getDeviceId();
    

    Returns undefined | string

  • getSessionId(): undefined | number
  • Returns current session ID.

    const sessionId = getSessionId();
    

    Returns undefined | number

  • getUserId(): undefined | string
  • Returns current user ID.

    const userId = getUserId();
    

    Returns undefined | string

  • Sends a group identify event containing group property operations.

    const id = new Identify();
    id.set('skills', ['js', 'ts']);
    const groupType = 'org';
    const groupName = 'engineering';
    groupIdentify(groupType, groupName, id);

    // alternatively, this tracking method is awaitable
    const result = await groupIdentify(groupType, groupName, id).promise;
    console.log(result.event); // {...}
    console.log(result.code); // 200
    console.log(result.message); // "Event tracked successfully"

    Parameters

    Returns Types.AmplitudeReturn<Types.Result>

  • Sends an identify event containing user property operations

    const id = new Identify();
    id.set('colors', ['rose', 'gold']);
    identify(id);

    // alternatively, this tracking method is awaitable
    const result = await identify(id).promise;
    console.log(result.event); // {...}
    console.log(result.code); // 200
    console.log(result.message); // "Event tracked successfully"

    Parameters

    Returns Types.AmplitudeReturn<Types.Result>

  • Initializes the Amplitude SDK with your apiKey, optional configurations. This method must be called before any other operations.

    await init(API_KEY, options).promise;
    

    Parameters

    Returns Types.AmplitudeReturn<void>

  • Removes a plugin.

    amplitude.remove('myPlugin');
    

    Parameters

    • pluginName: string

    Returns Types.AmplitudeReturn<void>

  • reset(): void
  • Anonymizes users after they log out, by:

    • setting userId to undefined
    • setting deviceId to a new uuid value

    With an undefined userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.

    import { reset } from '@amplitude/analytics-browser';

    reset();

    Returns void

  • Sends a revenue event containing revenue property operations.

    const rev = new Revenue();
    rev.setRevenue(100);
    revenue(rev);

    // alternatively, this tracking method is awaitable
    const result = await revenue(rev).promise;
    console.log(result.event); // {...}
    console.log(result.code); // 200
    console.log(result.message); // "Event tracked successfully"

    Parameters

    Returns Types.AmplitudeReturn<Types.Result>

  • setDeviceId(deviceId: string): void
  • Sets a new device ID. When setting a custom device ID, make sure the value is sufficiently unique. A uuid is recommended.

    setDeviceId('deviceId');
    

    Parameters

    • deviceId: string

    Returns void

  • Assigns a user to group

    const groupType = 'orgId';
    const groupName = '15';
    setGroup(groupType, groupName, { user_id: '12345' })

    Parameters

    • groupType: string
    • groupName: string | string[]
    • Optional eventOptions: Types.EventOptions

    Returns Types.AmplitudeReturn<Types.Result>

  • setOptOut(optOut: boolean): void
  • Sets a new optOut config value. This toggles event tracking on/off.

    // Stops tracking
    setOptOut(true);

    // Starts/resumes tracking
    setOptOut(false);

    Parameters

    • optOut: boolean

    Returns void

  • setSessionId(sessionId: number): void
  • Sets a new session ID. When settign a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).

    setSessionId(Date.now());
    

    Parameters

    • sessionId: number

    Returns void

  • Sets the network transport type for events.

    // Use Fetch API
    setTransport('fetch');

    // Use XMLHttpRequest API
    setTransport('xhr');

    // Use navigator.sendBeacon API
    setTransport('beacon');

    Parameters

    Returns void

  • setUserId(userId: undefined | string): void
  • Sets a new user ID.

    setUserId('userId');
    

    Parameters

    • userId: undefined | string

    Returns void

  • Tracks user-defined event, with specified type, optional event properties and optional overwrites.

    // event tracking with event type only
    track('Page Load');

    // event tracking with event type and additional event properties
    track('Page Load', { loadTime: 1000 });

    // event tracking with event type, additional event properties, and overwritten event options
    track('Page Load', { loadTime: 1000 }, { sessionId: -1 });

    // alternatively, this tracking method is awaitable
    const result = await track('Page Load').promise;
    console.log(result.event); // {...}
    console.log(result.code); // 200
    console.log(result.message); // "Event tracked successfully"

    Parameters

    Returns Types.AmplitudeReturn<Types.Result>

Generated using TypeDoc