Javascript API
The Userpilot Javascript SDK officially supports the following methods.
identify (userId, [properties])
Identifies the current user with an ID and an optional set of properties.
userpilot.identify("123", { name: "John", email: "john@example.com", created_at: "1519205055" // Additional user properties // projectId: "1" // trialEnds: '2019-10-31T09:29:33.401Z' });
anonymous
Assign a session based unique ID for the current user.
reload([URL])
userpilot.reload(); /* You can also call reload on a fake URL */ userpilot.reload({url: 'https://example.com/hello'});
Update Userpilot content when there is a change in the page state.
track (name, [properties])
userpilot.track("invitedAgent", { name: "Sam", email: "sam@example.com" });
Tracks a custom event taken by the current user.
trigger (contentId)
Force a certain Userpilot content to show for the current user. This method completely overrides any targeting conditions that have been set for that content.
on (event, callback)
Trigger a callback function on an event.
List of all the methods that will occur during an experience life cycle.
- started
Triggers when the flow starts.
{id: 1, token: 1576146927zJny2049}
- completed
Triggers when the flow gets completed.
{id: 1, token: 1576146927zJny2049}
- dismissed
Triggers when the flow gets dismissed.
{id: 1, token: 1576146927zJny2049}
- step
Triggers when there is an interaction with the UI pattern.
{id: 1, token: 1576146927zJny2049, step: 1, totalSteps: 15}
userpilot.on('completed', function(event){ alert('Experience completed'); });
off (event)
Remove a callback function attached to an event.
once (event, callback)
Trigger the callback function only once.
userpilot.end()
Ends the currently running flow. This can be used to stop an active flow in progress, allowing users to exit the flow at any stage as per your usecase.
userpilot.clean()
Clears the Userpilot storage, which removes all saved data related to user sessions and content activity. This is particularly useful when a user ID is still stored even though the user has logged out, causing content like RC (Resource Center) or flows to appear unexpectedly on the login page.
userpilot.destroy()
Fully clears the Userpilot storage and removes any active content on the page. This function can be used to ensure that flows and other Userpilot features operate correctly based on user authentication so that they do not show up for logged out users.