Userflow.js Installation

In order for your users to your flows in your web app, you need to install Userflow.js.

Userflow.js is a tiny piece of JavaScript code (~15 kB), which is loaded asynchronously in your web app, so it won’t affect your page load speed.

The installation is simple and only requires 3 quick steps:

Step 1: Choose installation method

Userflow.js can be installed in one of 3 ways:

App type Method
Browser apps using module bundlers<br/>(such as Webpack or Rollup) <br/>(npm installation) Step 2A Go to
Other browser apps <br/>(HTML installation) Step 2B Go to
Electron apps userflow-electron Use

Step 2A: npm installation

We recommend installing Userflow.js using the userflow.js npm package .

First, run this in your Terminal:

npm install userflow.js

Import and use the userflow object from the userflow.js module:

import userflow from 'userflow.js'

userflow.init('USERFLOW_TOKEN')
userflow.identify('USER_ID', {
  name: 'USER_NAME',
  email: 'USER_EMAIL',
  signed_up_at: 'USER_SIGNED_UP_AT'
})

Then to go Step 3 .

Step 2B: HTML installation

Only do this if you did not complete Step 2A.

Copy-paste the following snippet into your HTML document before the ending </body> tag:

<script type="text/javascript">
  ;(function() {
    var s = document.createElement('script')
    s.src = 'https://js.getuserflow.com/userflow.js'
    s.async = true
    document.head.appendChild(s)
    s.onload = function() {
      userflow.init('USERFLOW_TOKEN')
      userflow.identify('USER_ID', {
        name: 'USER_NAME',
        email: 'USER_EMAIL',
        signed_up_at: 'USER_SIGNED_UP_AT'
      })
    }
  })()
</script>

Step 3: Replace placeholders

In the code you copy-pasted above, replace USERFLOW_TOKEN with the Userflow.js Token you find under Settings -> Environments . Note that if you have multiple environments (e.g. Production and Staging) that each environment has a unique token.

Next, replace USER_ID with the currently signed in user’s ID in your database. Also replace USER_NAME , USER_EMAIL and USER_SIGNED_UP_AT with the user’s real values. signed_up_at should be specified in ISO 8601 format. Example: 2019-12-11T12:34:56Z .

The properties in userflow.identify ‘s second argument are all optional. They’re useful for looking up users in Userflow to e.g. see their flow progress, or to use in the flow content or conditions. If you don’t want to share this with Userflow, feel free to leave out the argument completely.

That’s it! Your Userflow installation is ready.

Optional: Custom attributes

Userflow.js supports sending custom attributes: Key-value pairs of data such as user role or other preferences. See Userflow.js Reference for how to use attributes.

Got questions? We're here for you!

The best way to get help is to
We usually reply within 5 minutes
You can also send an email to support@getuserflow.com
We usually reply within a few hours