Platform
JavaScript SDK
The window.OperatorStack SDK gives you programmatic control over all OperatorStack features.
Availability#
The SDK is available globally after the embed script loads. All async methods internally await the ready promise, so you can call them immediately without waiting.
// Option 1: Await the ready promiseawait window.OperatorStack.readyconsole.log('SDK is ready') // Option 2: Just call methods directly (they await internally)const result = await window.OperatorStack.joinWaitlist({ email: 'user@example.com'})Properties#
| Property | Type | Description |
|---|---|---|
| ready | Promise<void> | Resolves when the SDK has initialized and fetched configuration |
| projectKey | string | null | The project key from the script tag data-project attribute |
Methods#
joinWaitlist(params)#
Submit a waitlist signup programmatically. On success, the visitor’s referral code is saved to localStorage so isSignedUp() and getReferralLink() work on future visits.
const result = await window.OperatorStack.joinWaitlist({ email: 'user@example.com', name: 'Jane Doe' // optional})| Property | Type | Description |
|---|---|---|
| email * | string | Email address for the signup |
| name | string | Optional name for the signup |
Returns:Promise<{ referral_code: string, referral_link: string }>
submitForm(formKey, data)#
Submit data to a custom form by its form key.
await window.OperatorStack.submitForm('frm_abc123', { email: 'user@example.com', company: 'Acme Inc', budget: '$10k-50k'})| Property | Type | Description |
|---|---|---|
| formKey * | string | The form key (starts with frm_) |
| data * | object | Key-value pairs to submit |
Returns:Promise<void>
sendContactMessage(params)#
Send a contact form message.
await window.OperatorStack.sendContactMessage({ email: 'user@example.com', name: 'Jane Doe', subject: 'Pricing question', message: 'What are your enterprise plans?'})| Property | Type | Description |
|---|---|---|
| email * | string | Sender email address |
| name | string | Sender name |
| subject | string | Message subject |
| message | string | Message body |
Returns:Promise<void>
trackEvent(name, metadata?)#
Track a custom analytics event.
// Simple eventwindow.OperatorStack.trackEvent('button_click') // Event with metadatawindow.OperatorStack.trackEvent('pricing_clicked', { plan: 'pro', amount: 29.99})| Property | Type | Description |
|---|---|---|
| name * | string | Custom event name (lowercase, underscores only) |
| metadata | object | Optional key-value metadata for the event |
Returns:void (events are batched and sent asynchronously)
getShareLinks(referralCode, options?)#
Generate ready-to-use social sharing URLs with an embedded referral code. Typically called after a waitlist signup.
// After a waitlist signup, generate share linksconst result = await window.OperatorStack.joinWaitlist({ email: 'user@example.com'}) const links = window.OperatorStack.getShareLinks(result.referral_code, { text: 'Join the waitlist!' // optional custom share text}) // Use the linkswindow.open(links.twitter, '_blank')navigator.clipboard.writeText(links.copy)| Property | Type | Description |
|---|---|---|
| referralCode * | string | The referral code to embed in share URLs (e.g., from joinWaitlist result) |
| options.text | string | Custom share text for social platforms (default: "Check this out!") |
Returns:{ twitter, linkedin, email, whatsapp, copy }
Each property is a ready-to-use URL. The copy property is a plain URL for clipboard use.
isSignedUp()#
Check whether the current visitor has previously signed up for the waitlist. Reads from localStorage — no network request.
if (window.OperatorStack.isSignedUp()) { // Returning visitor — show share UI showShareUI()} else { // New visitor — show signup form showSignupForm()}Returns:boolean
getReferralLink()#
Get the current visitor’s referral link. Returns null if the visitor hasn’t signed up yet. No network request — reads from locally stored identity.
const ref = window.OperatorStack.getReferralLink()if (ref) { document.getElementById('share-link').textContent = ref.referral_link // Generate social share links from the code const links = window.OperatorStack.getShareLinks(ref.referral_code) window.open(links.twitter, '_blank')}Returns:{ referral_code: string, referral_link: string } | null
Common pattern: first visit vs. returning#
Use isSignedUp() and getReferralLink() together to show the right UI to new vs. returning visitors.
// First visit: sign up and show share linksif (!window.OperatorStack.isSignedUp()) { const result = await window.OperatorStack.joinWaitlist({ email: 'user@example.com' }) const links = window.OperatorStack.getShareLinks(result.referral_code) showShareUI(links)} // Returning visit: retrieve stored referral linkconst ref = window.OperatorStack.getReferralLink()if (ref) { const links = window.OperatorStack.getShareLinks(ref.referral_code) showShareUI(links)}getVisitorId()#
Get the current visitor’s persistent ID (stored in localStorage).
const visitorId = window.OperatorStack.getVisitorId()console.log(visitorId) // "550e8400-e29b-41d4-a716-446655440000" or nullReturns:string | null
showChat() / hideChat()#
Programmatically open or close the chat window.
// Open chat programmatically (e.g., from a "Chat with us" button)document.querySelector('#chat-btn').addEventListener('click', () => { window.OperatorStack.showChat()}) // Close chatwindow.OperatorStack.hideChat()TypeScript interface#
For TypeScript projects, here’s the full SDK interface:
interface OperatorStackSDK { ready: Promise<void> projectKey: string | null joinWaitlist(params: { email: string name?: string }): Promise<{ referral_code: string; referral_link: string }> submitForm(formKey: string, data: Record<string, unknown>): Promise<void> sendContactMessage(params: { email: string name?: string subject?: string message?: string }): Promise<void> trackEvent(name: string, metadata?: Record<string, unknown>): void isSignedUp(): boolean getReferralLink(): { referral_code: string referral_link: string } | null getVisitorId(): string | null getShareLinks( referralCode: string, options?: { text?: string } ): { twitter: string linkedin: string email: string whatsapp: string copy: string } showChat(): Promise<void> hideChat(): Promise<void>} declare global { interface Window { OperatorStack: OperatorStackSDK }}