> For the complete documentation index, see [llms.txt](https://docs.userlane.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.userlane.com/deployment/rollout/the-userlane-snippet.md). Agents can also search and read this documentation through its [MCP server](https://docs.userlane.com/~gitbook/mcp).

# 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.

{% hint style="info" %}
**The browser extension is the recommended deployment.** Use the snippet only for an application where the extension can't be deployed, and agree this with your Userlane team first. See [How Userlane is deployed](https://docs.userlane.com/deployment/rollout/how-userlane-is-deployed.md).
{% endhint %}

{% hint style="warning" %}
**Before you start.** You need admin rights in the Userlane Portal, a developer who can change the application's front-end code, an application that runs on a single domain, and Edge 79+, Firefox 60+, Chrome 70+, or Safari 12+.
{% endhint %}

{% columns %}
{% column %}
{% content-ref url="/pages/GIfweTU9uzaVjAhuIhz4" %}
[Use a client token](https://docs.userlane.com/deployment/rollout/the-userlane-snippet/use-a-client-token.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
{% content-ref url="/pages/ZQ57IWGiEUbd4abLRPyf" %}
[Use Subresource Integrity](https://docs.userlane.com/deployment/rollout/the-userlane-snippet/use-subresource-integrity.md)
{% endcontent-ref %}
{% endcolumn %}
{% endcolumns %}

## 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

{% stepper %}
{% step %}

#### Copy the snippet (admin)

In the Userlane Portal, go to **Settings > Application Settings > Snippet Setup** and copy the snippet. It already contains your property ID[^1]. Content becomes visible as soon as the snippet goes live, so keep chapters private until launch.
{% endstep %}

{% step %}

#### 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.

```javascript
// 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.
{% endstep %}
{% endstepper %}

## Identify users and pass attributes

Pass a stable user ID[^2] 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](https://docs.userlane.com/security-and-privacy/cookies-and-tracking-transparency.md).

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.

```javascript
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](https://docs.userlane.com/administration/attributes.md).

## 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.

```javascript
// see what a user with this attribute sees
Userlane('identify', 'test_user_ID', { attribute_key: 'example_value' });

// see content in another language
Userlane('lang', 'language_code');
```

{% hint style="success" %}
**Result.** The Assistant appears in the application, and users show in the Userlane Portal with the IDs you passed.
{% endhint %}

## Microsoft Dynamics 365

In Microsoft Dynamics 365, load Userlane through a hidden button on the global command bar, so it runs on every page:

1. Add a ribbon button[^3] to the global command bar, `Mscrm.GlobalTab`, under Application Ribbons.
2. Call the snippet from the button's enable rule, so it runs without a click.
3. Return `false` from the enable rule, so the button stays hidden.
4. Add `window.top.` before every Userlane command, for example `window.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 `init` or `identify`. 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](https://docs.userlane.com/deployment/rollout/the-userlane-snippet/use-a-client-token.md) or [Subresource Integrity](https://docs.userlane.com/deployment/rollout/the-userlane-snippet/use-subresource-integrity.md).

## Troubleshooting

| Problem                                             | Cause                                                                              | Fix                                                                                                                            |
| --------------------------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| 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](https://docs.userlane.com/deployment/rollout/environment-prerequisites.md) |
| 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

{% content-ref url="/pages/GIfweTU9uzaVjAhuIhz4" %}
[Use a client token](https://docs.userlane.com/deployment/rollout/the-userlane-snippet/use-a-client-token.md)
{% endcontent-ref %}

{% content-ref url="/pages/ZQ57IWGiEUbd4abLRPyf" %}
[Use Subresource Integrity](https://docs.userlane.com/deployment/rollout/the-userlane-snippet/use-subresource-integrity.md)
{% endcontent-ref %}

{% content-ref url="/pages/fsyxQCU0NHHxdU55aS9u" %}
[How Userlane is deployed](https://docs.userlane.com/deployment/rollout/how-userlane-is-deployed.md)
{% endcontent-ref %}

{% content-ref url="/pages/JaoydeD5UPCYFS9NuupA" %}
[Quick reference of commands](https://docs.userlane.com/developer-reference/quick-reference-of-commands.md)
{% endcontent-ref %}

{% content-ref url="/pages/gtcOzAVjL7zzv75As2Jd" %}
[Attributes](https://docs.userlane.com/administration/attributes.md)
{% endcontent-ref %}

## FAQ

<details>

<summary>Does the snippet need the browser extension?</summary>

No. The snippet loads Userlane on its own in the application where it is installed.

</details>

<details>

<summary>Does App Discovery work with the snippet?</summary>

No. App Discovery needs the browser extension.

</details>

<details>

<summary>Where is the property ID for the snippet?</summary>

The property ID is in the Userlane Portal under Settings > Application Settings > Snippet Setup.

</details>

<details>

<summary>What happens if the snippet passes no user ID?</summary>

Userlane generates a random user ID and stores it in a cookie in that browser.

</details>

[^1]: The property ID tells Userlane which application in the Portal the snippet belongs to.

[^2]: A user ID is your own identifier for a person, such as an employee number, passed to Userlane with the `identify` command.

[^3]: A ribbon button is a command button in the Dynamics 365 command bar, defined in the application's ribbon configuration.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.userlane.com/deployment/rollout/the-userlane-snippet.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
