Skip to content

UMD build (legacy)

If you are not using React, or need to load the SDK dynamically without a build step, use the UMD (Universal Module Definition) build. The UMD build works in vanilla JavaScript, jQuery projects, and any HTML environment.

How it works

The UMD build bundles all dependencies (React, React DOM, TanStack Query) as a self-contained JavaScript file. You do not need to manage React in your application - the SDK brings its own.

Setup

StepDescription
1Load peer dependencies (React, React DOM, TanStack Query) from CDN.
2Load the SDK from CDN.
3Initialize and mount the Copilot component into your container.

Example

<!-- Step 1: Load peer dependencies -->
<script src="https://docs.gocommotion.com/react-18-prod.min.js"></script>
<script src="https://docs.gocommotion.com/reactdom-18-prod.min.js"></script>
<script src="https://docs.gocommotion.com/react-query-4-prod.js"></script>
<!-- Step 2: Load the SDK -->
<script src="https://ai-copilot.gocommotion.com/fallback/index.umd.js"></script>
<!-- Step 3: Initialize and mount -->
<div id="copilot-container"></div>
<script>
const sdk = window.initializeCommotionSDK('YOUR_APP_KEY');
const copilot = sdk.Copilot.init({
containerId: 'copilot-container',
mode: 'embed',
userId: 'user-123',
});
</script>

Initialization reference

Function / optionTypeRequiredDescription
window.initializeCommotionSDKfunctionYesInitializes the SDK and returns the Copilot component factory.
appKeystringYesYour organization’s app key.
sdk.Copilot.initfunctionYesMounts the chat interface into a DOM container.
containerIdstringYesThe HTML element ID where the chat will render.
userIdstringNoUnique identifier for the current user. Auto-generated if omitted.
modestringYesApplication mode: embed, preview, link_preview, or widget.

UMD-specific props

PropTypeRequiredDescription
containerIdstringYesDOM element ID where Copilot will mount.

Instance methods

The UMD build returns an instance object with cleanup methods:

const instance = sdk.Copilot.init({
containerId: 'copilot-root',
mode: 'embed',
userId: 'user-123',
});
// Cleanup when done
instance.destroy();
MethodDescription
destroy()Unmounts the Copilot component and cleans up event listeners.

When to use UMD

ScenarioUse UMD?
No React or build systemYes
Legacy or static siteYes
Dynamic SDK loadingYes
Integrating into WordPress, ShopifyYes
Modern React 18+ applicationNo - use the React build