Install the snippet
How to add the Userlane snippet to a web application, identify users, and check that Userlane loads.
Add the Userlane snippet to your application's code so Userlane loads for every user without the browser extension.
What the snippet covers
The snippet loads Userlane inside the one application it is installed in, identifies your users, and can pass their attributes, so targeting and analytics work as they do with the extension. App Discovery and Portfolio Overview need the browser extension and show no data from a snippet-only setup. Guides that span several domains are not supported, because Userlane can't carry context from one domain to the next.
Add the snippet
Add it to the application (developer)
Place the snippet in the front-end code before the closing </body> tag, so it runs on every page.
// load Userlane
(function(i,s,o,g,r,a,m){i['UserlaneCommandObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)};a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://cdn.userlane.com/userlane.js','Userlane');
// identify the user
Userlane('identify', 'user_ID');
// initialize Userlane
Userlane('init', 'property_ID');Only the load part and init are required; every other command is optional. Call any other command before init. If identify runs after init, Userlane creates a generated user instead of using your ID.
Identify users and pass attributes
Pass a stable user ID with identify. It lets you target content and read analytics per user, and it shows users which guides they have already completed. Without one, Userlane generates a random ID and keeps it in a cookie, so the same person can show up as several users after clearing cookies or switching browsers. See Cookies and tracking transparency.
To target content by role, region, or similar, add attributes to the same command. Values can be numbers, strings, dates, arrays, or booleans. Userlane updates this information every time the page loads.
Userlane('identify', 'user_ID', {
attribute_key: 'attribute_value'
});Create each attribute in the Userlane Portal first. The snippet doesn't create attributes, and values for attributes that don't exist are discarded. See Attributes.
Test as a specific user
Sign out of the Userlane Portal, open the browser console on a page where the snippet runs, and enter a command to see what a particular user or language gets. The change lasts until the page reloads.
Microsoft Dynamics 365
In Microsoft Dynamics 365, load Userlane through a hidden button on the global command bar, so it runs on every page:
Add a ribbon button to the global command bar,
Mscrm.GlobalTab, under Application Ribbons.Call the snippet from the button's enable rule, so it runs without a click.
Return
falsefrom the enable rule, so the button stays hidden.Add
window.top.before every Userlane command, for examplewindow.top.Userlane('init', 'property_ID');.
Good to know
Disabling an application URL in the Portal doesn't stop the snippet. Remove the snippet from those pages instead.
End users should get Userlane from either the snippet or the browser extension on a page, not both. Content creators can still use the browser extension to build and test content.
If the application shows another application in a cross-origin iframe, add only the load part of the snippet inside the iframe, without
initoridentify. Add the iframe's domain in the Userlane Portal so the Editor works there.Each snippet is tied to one Userlane account.
For extra security, add a client token or Subresource Integrity.
Troubleshooting
Userlane doesn't appear
The snippet or init is missing on the page, or the property ID is wrong
Check the page source and compare the property ID with Snippet Setup
Userlane doesn't appear
The application's Content Security Policy blocks Userlane
Add the hosts listed in Environment prerequisites
Users appear twice or as generated users
identify runs after init, or passes no ID
Move identify before init and pass a stable ID
Content such as the Welcome Slide keeps reappearing
No user ID was passed, so progress sits in a cookie that was cleared
Pass a user ID with identify
Attributes show as not set
The attribute doesn't exist in the Portal, or values are nested in an extra object
Create the attribute and pass values as in the example above
Commands don't run in Dynamics 365
window.top. is missing
Add it before every Userlane command
Related articles
Use a client tokenUse Subresource IntegrityHow Userlane is deployedQuick reference of commandsAttributesFAQ
Last updated
Was this helpful?

