Userflow.js installation in Google Tag Manager

You can install Userflow.js via Google Tag Manager (GTM).


Your GTM account must have an existing variable that contains the currently signed-in user’s ID. Optionally, you can also use variables for other attributes such as the user’s name, email, when they signed up etc.

In this guide, we assume you’ve named your user ID variable userId. If you’ve used a different name, then please replace the {{userId}} part in the snippet below accordingly.


Follow these steps:

  1. Sign into Userflow.
  2. Go to SettingsEnvironments.
  3. Note down your Userflow.js Token (you’ll need it in a later step). Hint: It starts with ct_.
  4. Sign into your Google Tag Manager account.
  5. Go to Tags.
  6. Click New.
  7. Click Tag Configuration.
  8. Click Custom HTML.
  9. In the HTML field, paste the code below (make sure to replace USERFLOW_TOKEN with the real token you noted down in step 3).
  10. Click Triggering.
  11. Click All pages, or another more suitable trigger if you have one.
  12. Click Save and give the tag a name, such as “Userflow”.
  !function(){var e="undefined"==typeof window?{}:window,t=e.userflow;if(!t){var r="";t=e.userflow={_stubbed:!0};var n=e.USERFLOWJS_QUEUE=e.USERFLOWJS_QUEUE||[],o=function(e){t[e]=function(){var;i(),n.push([e,null,t])}},s=function(e){t[e]=function(){var t,;i();var o=new Promise((function(e,r){t={resolve:e,reject:r}}));return n.push([e,t,r]),o}},a=function(e,r){t[e]=function(){return r}},u=!1,i=function(){if(!u){u=!0;var t=document.createElement("script");t.async=!0;var n=e.USERFLOWJS_ENV_VARS||{};"es2020"===(n.USERFLOWJS_BROWSER_TARGET||function(e){for(var t=[[/Edg\//,/Edg\/(\d+)/,80],[/OPR\//,/OPR\/(\d+)/,67],[/Chrome\//,/Chrome\/(\d+)/,80],[/Safari\//,/Version\/(\d+)/,14],[/Firefox\//,/Firefox\/(\d+)/,74]],r=0;r<t.length;r++){var n=t[r],o=n[0],s=n[1],a=n[2];if(e.match(o)){var u=e.match(new RegExp(s));if(u&&parseInt(u[1],10)>=a)return"es2020";break}}return"legacy"}(navigator.userAgent))?(t.type="module",t.src=n.USERFLOWJS_ES2020_URL||r+"es2020/userflow.js"):t.src=n.USERFLOWJS_LEGACY_URL||r+"legacy/userflow.js",t.onerror=function(){u=!1,console.error("Could not load Userflow.js")},document.head.appendChild(t)}};o("_setTargetEnv"),o("closeResourceCenter"),o("init"),o("off"),o("on"),o("prepareAudio"),o("registerCustomInput"),o("remount"),o("reset"),o("setCustomInputSelector"),o("setCustomNavigate"),o("setCustomScrollIntoView"),o("setInferenceAttributeFilter"),o("setInferenceAttributeNames"),o("setInferenceClassNameFilter"),o("setResourceCenterLauncherHidden"),o("setScrollPadding"),o("setShadowDomEnabled"),o("setPageTrackingDisabled"),o("setUrlFilter"),o("openResourceCenter"),o("toggleResourceCenter"),s("endAll"),s("endAllFlows"),s("endChecklist"),s("group"),s("identify"),s("identifyAnonymous"),s("start"),s("startFlow"),s("startWalk"),s("track"),s("updateGroup"),s("updateUser"),a("getResourceCenterState",null),a("isIdentified",!1)}}();

  userflow.identify('{{userId}}', {
    // Put any additional attributes here (see below)

IMPORTANT: Make sure to replace USERFLOW_TOKEN with the Userflow.js Token you find in Userflow under Settings -> Environments .

Extra custom attributes

You can pass whatever custom attributes you want to Userflow in the userflow.identify() call. You can use these attributes to target flows to specific users, e.g. only show a welcome modal to new users based on when they signed up.

If your GTM account contains other variables, such as the user’s name, email or when they signed up, you can add these attributes in the second argument of the userflow.identify() call. Example:

userflow.identify('{{userId}}', {
  name: '{{name}}',
  email: '{{email}}',
  signed_up_at: '{{signed_up_at}}'

This above code expects your 3 extra variables to be named name, email, and signed_up_at in GTM. Note that the value of the signed_up_at attribute must be in ISO-8601 format (example: 2021-03-26T12:31:47Z).

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
We usually reply within a few hours