Flush all unsent events.
flush();
Returns current device ID.
const deviceId = getDeviceId();
Returns current session ID.
const sessionId = getSessionId();
Returns current user ID.
const userId = getUserId();
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"
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"
Initializes the Amplitude SDK with your apiKey, optional configurations. This method must be called before any other operations.
await init(API_KEY, options).promise;
Alias for track()
Removes a plugin.
amplitude.remove('myPlugin');
Anonymizes users after they log out, by:
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();
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"
Sets a new device ID. When setting a custom device ID, make sure the value is sufficiently unique. A uuid is recommended.
setDeviceId('deviceId');
Assigns a user to group
const groupType = 'orgId';
const groupName = '15';
setGroup(groupType, groupName, { user_id: '12345' })
Sets a new optOut config value. This toggles event tracking on/off.
// Stops tracking
setOptOut(true);
// Starts/resumes tracking
setOptOut(false);
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());
Sets the network transport type for events.
// Use Fetch API
setTransport('fetch');
// Use XMLHttpRequest API
setTransport('xhr');
// Use navigator.sendBeacon API
setTransport('beacon');
Sets a new user ID.
setUserId('userId');
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"
Generated using TypeDoc
Adds a new plugin.