Once the HelpHero script loads it makes a global object HelpHero
object available to your web page. This allows your to interact with HelpHero from your own scripts, meaning you can start & stop tours, listen to events and more. The following methods are available on the global HelpHero
object.
HelpHero.identify(userId, [properties])
Identify the current user with a userId (string or number) and an optional set of user properties (object).
HelpHero.identify("<USER_ID>", { name: "<NAME>", role: "<USER_ROLE>" });
if (userId != null && !/^s*$/.test(userId)) { HelpHero.identify(userId); }
HelpHero.identify(location.hostname + userId);
HelpHero.anonymous()
Generates a unique user id which will be persisted in the user’s browser until the browser cache is cleared.
HelpHero.update(properties)
Calling the update method with an object of user properties will update those fields on the current user and then check if any tours should be auto started based on the new properties.
HelpHero.update({ hasPlan: true });
Or pass function to update based on current properties
HelpHero.update(function(currentProperties) { return { hasPlan: !currentProperties.hasPlan }; });
HelpHero.startTour(tourId, [options])
Starts tour with the specified tour id. The tour will only start if the user is on an URL that matches the starting URL match specified in the tour. How do you find your tourId?
Start tour even if user has already seen tour:
HelpHero.startTour("<TOUR_ID>")
Options you can pass to override the default behavior of startTour
skipIfAlreadySeen: boolean
HelpHero.startTour("<TOUR_ID>", { skipIfAlreadySeen: true })
redirectIfNeeded: boolean
HelpHero.startTour("<TOUR_ID>", { redirectIfNeeded: true })
stepId: string
HelpHero.startTour("<TOUR_ID>", { stepId: "<STEP_ID>" })
HelpHero.advanceTour([options])
The current active tour is moved forward one step. Is ignored when current step is a highlight which requires the user to click within highlighted area.
HelpHero.advanceTour()
Options you can pass to override the default behavior of advanceTour
stepId: string | number
Alternatively you can pass a number to move the tour a relative number of steps from the current step. For example to move the tour back 2 steps:HelpHero.advanceTour({ stepId: "<STEP_ID>" })
HelpHero.advanceTour({ stepId: -2 })
HelpHero.cancelTour()
The current active tour is immediately cancelled.
HelpHero.startChecklist(checklistId)
Starts checklist with the specified checklist id. The checklist will only start if:
HelpHero.openChecklist()
Opens the checklist if there is one available for the current page.
HelpHero.closeChecklist()
Closes the checklist if there is one available for the current page.
HelpHero.setOptions(options)
Allows you to set HelpHero options by passing an object which can contain any of the following:
show: boolean
HelpHero.setOptions({ show: false })
showBeacon: boolean
HelpHero.setOptions({ showBeacon: false })
navigate: (url: string) => void
function handleNavigate(url) {
// use history or your frameworks router to change location
// if using history please ensure your app responds to history changes
try {
history.pushState({}, '', url);
} catch (err) {
location.assign(url);
}
}
HelpHero.setOptions({ navigate: handleNavigate });
HelpHero.reset()
Calling reset stops all HelpHero content such as tours, hotspots and checklists from being displayed until either HelpHero.identify
orHelpHero.anonymous
is called again.
HelpHero.reset
before calling either HelpHero.anonymous
orHelpHero.identify
.HelpHero.on([eventName], listenerFn, [context])
Registering a listener for all events:HelpHero.on("tour_started", function(event, info) { console.log(event, info); })
HelpHero.on(function(event, info) { console.log(event, info); })
type EventKind = | "tour_started" | "tour_completed" | "tour_advanced" | "tour_backtracked" | "tour_cancelled" | "tour_interrupted"; type Event = { kind: EventKind; tourId: string; stepId: string; };
type Step = { id: string; name: string; }; type Tour = { id: string; name: string; }; type Info = { tour: Tour; step: Step; };
type EventKind = | "checklist_item_completed" | "checklist_completed"; type Event = { kind: EventKind; checklistId: string; itemId: ?string; };
type ChecklistItem = { id: string; name: string; }; type Checklist = { id: string; name: string; items: ChecklistItem[]; }; type Info = { checklist: Checklist; item: ?ChecklistItem; };
type EventKind = | "hotspot_visited" | "hotspot_dismissed"; type Event = { kind: EventKind; hotspotId: string; };
type Hotspot = { id: string; name: string; }; type Info = { hotspot: Hotspot; };
HelpHero.off([eventName], listenerFn, [context])
Unregister a previously registered listener. Use the same arguments that you passed when registering the listener with HelpHero.on
.