Script loading
Async script tag, the command-queue loader, and waiting for window.motisig.
The hosted script exposes a global window.motisig. Because the script loads asynchronously, calls made before it finishes need either the command-queue loader or a wait helper.
Async script tag (auto-init)
<script
src="https://motisig.ai/cdn/web/v1/motisig.js"
data-sdk-key="YOUR_SDK_KEY"
data-project-id="YOUR_PROJECT_ID"
async
></script>The script auto-initializes from data-* attributes and replays any queued calls. After load, window.motisig exposes initialize, identify, event, updateUser, addTags, removeTags, addOrUpdateAttributes, removeAttributes, getUser, logout, and reset.
Command-queue loader (manual init)
Use this when you need to call the API before the async script has loaded. It defines a stub that queues calls and replays them once the real SDK arrives.
<script>
!function(){if(!window.motisig||!window.motisig.methods){var m=window.motisig=window.motisig||[];
m.methods=["initialize","identify","event","updateUser","addTags","removeTags","addOrUpdateAttributes","removeAttributes","reset"];
m.factory=function(method){return function(){var a=Array.prototype.slice.call(arguments);a.unshift(method);m.push(a);return m;};};
for(var i=0;i<m.methods.length;i++){m[m.methods[i]]=m.factory(m.methods[i]);}
var s=document.createElement("script");s.async=!0;s.src="https://motisig.ai/cdn/web/v1/motisig.js";
var f=document.getElementsByTagName("script")[0];f.parentNode.insertBefore(s,f);}}();
motisig.initialize({ sdkKey: "YOUR_SDK_KEY", projectId: "YOUR_PROJECT_ID" });
motisig.event("signup.clicked", { plan: "pro" });
</script>Automatic page.viewed engagement tracking is enabled by default on the async script tag (data-auto-page-view defaults to true). Manual event() calls use eventCategory: custom with any event name you choose.
Use the async tag or the command-queue loader — not both.
Waiting for the global
In code paths that may run before the script loads (for example an auth callback), poll for window.motisig:
async function waitForMotisig(timeoutMs = 10000) {
const start = Date.now();
while (Date.now() - start < timeoutMs) {
if (window.motisig?.identify) return window.motisig;
await new Promise((r) => setTimeout(r, 50));
}
return null;
}
const motisig = await waitForMotisig();
if (motisig) await motisig.identify(userId, { email });