@deway-ai/web-sdk
v0.68.0
Published
Deway's Web SDK
Readme
Deway Web SDK
Software should adapt to users — not the other way around.
Deway is your AI assistant that learns your product, embedding proactive guidance directly into your web app. Scale expert knowledge across your entire user base with real-time, intelligent assistance that continuously improves with every interaction.
Quick Install with AI Assistant
Let AI help AI. Copy this prompt to your coding assistant (Claude, Copilot, etc.) to get Deway integrated with best practices for your specific framework:
Install and integrate the Deway Web SDK (@deway-ai/web-sdk) into my project.
PACKAGE INFO:
- Name: @deway-ai/web-sdk
- Purpose: Lightweight TypeScript SDK that adds an AI-powered user engagement engine
- Supports: React, Next.js, Vue, Nuxt, Angular, and vanilla JS
- Includes full TypeScript definitions
TASKS:
1. Detect my framework and package manager (npm, pnpm, or yarn) from lock files
2. Install the SDK using the detected package manager
3. For vanilla JS/HTML projects: Use the CDN script instead:
<script src="https://unpkg.com/@deway-ai/web-sdk/dist/loader.umd.js"></script>
4. Initialize early in the app lifecycle (use appropriate lifecycle hook for the framework):
- Import: import Deway from '@deway-ai/web-sdk'
- Call Deway.init() with the appKey:
Deway.init({ appKey: 'your-deway-app-key' })
5. Identify users after authentication:
if (user?.id) Deway.identify(user.id);
IMPLEMENTATION NOTES:
- Follow my existing project structure and code style conventions
- Use appropriate lifecycle hooks: React (useEffect), Vue (onMounted), Angular (ngOnInit)
FIRST analyze my project structure and detect the framework and package manager. Then and only then implement the Deway Web SDK integration accordingly.Installation
Add Deway to your project with your preferred package manager:
npm install @deway-ai/web-sdk
# or
pnpm add @deway-ai/web-sdk
# or
yarn add @deway-ai/web-sdkQuick Start
Basic Integration
import Deway from '@deway-ai/web-sdk';
// Initialize the SDK
Deway.init({
appKey: 'your-app-key'
});
// Identify users for personalized experiences
Deway.identify('user-123');Note: Methods can be called immediately and are queued until initialization completes. For best results, call Deway.init() early in your app lifecycle to start learning user patterns from the first interaction.
HTML/JavaScript Integration
<script src="https://unpkg.com/@deway-ai/web-sdk/dist/loader.umd.js"></script>
<script>
Deway.init({
appKey: 'your-app-key'
});
Deway.identify('user-123');
</script>Configuration
Deway keeps configuration simple—just provide your app key and we handle the rest:
Deway.init({
appKey: string, // Required: Your Deway app key
});Why so simple? Themes, feature flags, AI prompts, and behavior settings are managed remotely and adapt automatically. This lets you iterate on user experiences without SDK updates or app deployments.
API Reference
Deway.init(config)
Start learning your product and embedding intelligent guidance into your app. Call this early in your app lifecycle to begin building user-specific insights (commands are queued until initialization completes).
Deway.identify(userId)
Connect a user ID to enable personalized, context-aware assistance that adapts to their unique journey.
Deway.reportEvent(name, params)
Track custom events to help Deway understand your product's unique workflows and provide smarter, context-aware guidance.
Parameters:
name(string): Event name (will be normalized: trimmed, lowercased, special characters replaced with underscores)params(object): Event parameters as a plain object
Example:
Deway.reportEvent('Product Purchased', {
product_id: 'ABC-123',
quantity: 5,
price: 99.99
});
// Event sent with normalized name: "product_purchased"Deway.setUserProfile(userProfile)
Enrich user profiles to enable deeper personalization and more intelligent assistance tailored to each user's context.
Parameters:
userProfile(object): User profile data as a plain object. Can contain any JSON-serializable properties.
Example:
Deway.setUserProfile({
name: 'Jane Doe',
email: '[email protected]',
age: 28,
preferences: {
theme: 'dark',
notifications: true
}
});Notes:
- Profile is upserted (created if new, replaced if exists)
- Profile data completely replaces existing profile on each call
Deway.show(config?)
Display the AI assistant interface that adapts to your users' needs. Choose the appearance that fits your product best.
interface EntrypointWidgetConfig {
appearanceMode?: "bookmark" | "bubble"; // Display mode (default: "bookmark")
}Appearance Modes:
"bookmark": Edge-pinned vertical tab for persistent, non-intrusive access (default)"bubble": Floating ellipsoid pill at bottom-right for prominent visibility
Deway.hide()
Temporarily hide the AI assistant interface while keeping the intelligent learning active in the background.
Deway.openChat()
Programmatically open the chat interface to guide users exactly when they need assistance. Perfect for contextual help triggers.
Example:
// Open chat via a custom button
document.getElementById('my-chat-button').addEventListener('click', () => {
Deway.openChat();
});Notes:
- The SDK must be initialized before calling this method
- Calling before initialization will log a warning
- This hides the entrypoint widget (same as clicking it)
Deway.isVisible()
Check if the interface is currently visible.
Deway.isInitialized()
Check if the SDK has completed initialization.
Deway.resetUserLocally()
Reset the current user's session and clear all locally stored user data without destroying the SDK. This removes all user identification, chat history, and preferences from localStorage and sessionStorage, allowing you to start fresh with a new user on the same device.
Use Cases:
- User logout/sign out flows
- Switching between user accounts
- Testing with clean user state
- Privacy-focused features that clear user data on demand
Example:
// User clicks logout button
document.getElementById('logout-button').addEventListener('click', () => {
Deway.resetUserLocally();
// SDK remains active and ready for new user identification
});Notes:
- SDK remains initialized and active after reset
- Clears all user-specific data from both localStorage and sessionStorage
- Removes the chat interface and options menu
- Can be called immediately after reset to identify a new user
- Safe to call multiple times
Deway.registerSupportCallback(callback)
Register a custom callback that fires when the user clicks the "Talk to Support" button in the chat interface. Overwrites any previously registered callback.
Parameters:
callback(() => void | Promise<void>): Function called when the support button is clicked. If it throws or returns a rejected Promise, Deway falls back to the remotely configured support behavior (URL redirect or selector guide).
Example:
Deway.registerSupportCallback(async () => {
// Open your own support widget
await openChat();
});Notes:
- Only one callback can be active at a time — subsequent calls replace the previous one
- If the callback throws or rejects, Deway automatically falls back to the server-configured support mode
- Call
Deway.unregisterSupportCallback()to restore default server-configured behavior
Deway.unregisterSupportCallback()
Remove the registered support callback and restore the default server-configured support behavior (URL redirect or selector guide).
Example:
Deway.unregisterSupportCallback();Deway.destroy()
Clean up SDK resources and stop all tracking.
Framework Examples
Deway adapts seamlessly to your framework of choice. Here's how to integrate intelligent user assistance into popular frameworks:
React
import {useEffect} from 'react';
import Deway from '@deway-ai/web-sdk';
function App() {
useEffect(() => {
Deway.init({
appKey: 'your-app-key'
});
// Enable personalized assistance when user is known
if (user?.id) {
Deway.identify(user.id);
}
}, [user?.id]);
return <div>Your App</div>;
}Vue
<script setup>
import {onMounted} from 'vue';
import Deway from '@deway-ai/web-sdk';
onMounted(() => {
Deway.init({
appKey: 'your-app-key'
});
});
</script>Angular
import {Component, OnInit} from '@angular/core';
import Deway from '@deway-ai/web-sdk';
@Component({
selector: 'app-root',
template: '<div>Your App</div>'
})
export class AppComponent implements OnInit {
ngOnInit() {
Deway.init({
appKey: 'your-app-key'
});
}
}What You Get
- Proactive AI Guidance: Intelligent assistance that learns your product and adapts to each user's journey
- Real-time Issue Prevention: Detect and resolve problems before users encounter them
- Continuous Learning: Self-improving knowledge graph that gets smarter with every interaction
- Scaled Expert Knowledge: Give every user the experience of having a dedicated specialist
- Seamless Integration: Works with React, Vue, Angular, and vanilla JavaScript
- Zero Configuration Overhead: Feature flags, themes, and AI prompts managed remotely
- Performance First: ~5KB loader with dynamic backend loading and offline resilience
- Full TypeScript Support: Complete type definitions for a superior developer experience
How Deway Adapts for You
Graceful Error Handling
The SDK handles all errors internally with intelligent recovery. No try-catch blocks needed—failed operations are logged and retried automatically so your app stays resilient.
Persistent User Context
User identification and preferences persist across sessions via localStorage. Once identified, users receive continuous personalized assistance until you explicitly call Deway.destroy() or clear storage.
Idempotent Initialization
Multiple Deway.init() calls are safe and ignored after the first. The SDK adapts to your initialization patterns without breaking.
Smart Retry Logic
Failed network operations automatically retry with exponential backoff. The SDK handles connectivity issues gracefully—no manual intervention required.
Intelligent Command Queuing
Call SDK methods immediately without waiting for initialization. Commands queue automatically and execute once the backend loads—your code stays simple while Deway handles the complexity.
Troubleshooting
Interface doesn't appear
Deway adapts its visibility to your configuration. Check these common solutions:
- Verify
Deway.init()was called with a validappKey - Enable auto-show in your remote configuration, or call
Deway.show()manually - Confirm initialization completed using
Deway.isInitialized() - Check browser console for initialization errors—the SDK logs helpful guidance
User identification not working
For personalized experiences to activate:
- Call
Deway.init()beforeDeway.identify()—initialization must complete first - Ensure user ID is a non-empty string
- Check browser console for diagnostic logs—Deway provides clear error messages
Commands not executing
Deway's intelligent command queue handles this automatically:
- Commands called before initialization are queued and execute once ready
- Check
Deway.isInitialized()to confirm the SDK is ready - Review browser console for any initialization errors—Deway adapts and retries when possible
