Userflow.js is the JavaScript library you install in your web app so Userflow can identify your users and show them flows, checklists and other content. This page explains the Userflow.js methods teams use most. Every method, with its parameters and code samples, is in the full Userflow.js reference. To install Userflow.js, see Userflow.js Installation.
Which Userflow.js methods does every install need?
Most Userflow.js installs call these methods on every page load, in this order:
userflow.init(token)connects Userflow.js to your Userflow environment. Find the token under Settings → Environments. Each environment, such as Production and Staging, has its own token.userflow.identify(userId, attributes)tells Userflow who the signed-in user is. Call it on every page load where a user is signed in. Attributes you send are added to the user's existing attributes.userflow.group(groupId, attributes)links the user to a company or group, if you use groups. Whether groups are available depends on your plan.
To record something a user did, call userflow.track(eventName, attributes) after identify.
How do I send user attributes with Userflow.js?
Userflow.js sends attributes as an object in identify, updateUser, group and track. Use userflow.updateUser(attributes) to change attributes after identify without identifying the user again. Setting an attribute to null removes it. Attribute names can use letters, numbers, underscores, dashes and spaces. The Attributes section of the reference covers data types and operations like adding to a number or a list.
How do I show Userflow to visitors who aren't signed in?
Userflow.js can identify visitors who aren't signed in with userflow.identifyAnonymous(). It gives the visitor an ID that's stored in their browser and reused on later visits. Use it only for visitors who aren't signed in. Each anonymous visitor counts toward your monthly active users. See How Userflow Tracks and Bills Monthly Active Users (MAUs).
What should Userflow.js do when a user signs out?
Call userflow.reset() when a user signs out of your app. Userflow.js forgets the current user and hides any content that's showing.
How do I start or end a flow from my own code?
Userflow.js can start content from your app's code with userflow.start(contentId). Find the content ID on the content's Link/Embed tab. Add {once: true} to start it only if the user hasn't seen it before. To hide all content that's showing, call userflow.endAll().
How do I control the Resource Center from Userflow.js?
Userflow.js can open, close and toggle the Resource Center with openResourceCenter(), closeResourceCenter() and toggleResourceCenter(). To use your own button instead of the default Resource Center launcher, call setResourceCenterLauncherHidden(true) after init, and use getResourceCenterState() to show counts like unread announcements. See Resource Center.
Which Userflow.js settings fix common app-specific problems?
Userflow.js has settings for apps that need different behavior:
Single-page apps:
setCustomNavigate()makes Go to page actions use your app's router instead of a full page load.Content showing behind your app's modals:
setBaseZIndex()raises the z-index Userflow places its content at.Sensitive data in URLs:
setUrlFilter()removes parts of the URL before it's sent to Userflow.Elements not found after a deploy: the inference filters stop Userflow.js from relying on class names or IDs that change. See Element inference: keep Userflow finding elements when class names or IDs change.
Custom dropdowns or combo boxes:
registerCustomInput()lets conditions read them like text inputs.Page view events:
setPageTrackingDisabled(true)stops automaticpage_viewedevents.Security:
disableEvalJs()blocks Evaluate JavaScript actions.Load failures:
load()lets you catch errors when Userflow.js can't load, for example because of a Content Security Policy. See Content Security Policy.