Using Appcues with RequireJS (Developer)
Learn how to Appcues can be used with AMD loaders like RequireJS.
Table of Contents
Appcues can be used with AMD loaders, like RequireJS. If you used an AMD loader on your site, you'll want to read this doc. There are two scenarios:
- You're loading Appcues as a window global and don't want it registered as module within your application
- Or, you're trying to load Appcues as a module inside your application
Loading Appcues as a window global while RequireJS is present on the page
If your site uses an AMD loader, like RequireJS, to load modules, Appcues will attempt to define itself as a module once it detects the AMD loader on the page. If you're not actually planning to use Appcues as module in your application but instead want it be defined as window global, you'll need to set an option on the page to tell the Appcues script to defer defining itself as an AMD module and instead proceed to define itself as a window global. This can be accomplished by adding an AppcuesSettings object to the window. This code should be placed directly before the <script> tag for the Appcues:
<script type="text/javascript">
window.AppcuesSettings = {
skipAMD: true
};
</script>
Loading Appcues as a module in your application
If you'd like to load Appcues through an AMD loader, like RequireJS, you can load it using the following snippet:
requirejs.config({
"paths": {
"appcues": "//fast.appcues.com/<your_appcues_id>.js"
}
});
Later in your app, you can access the Appcues library with something like this:
// As an example, we identify the user
define(['models/user', 'appcues'], function(user, Appcues) {
Appcues.identify(user.id, {
email: user.email,
name: user.first_name + ' ' + user.last_name
});
});