Core SDK Methods
Complete reference for all Deway SDK methods.
Deway.init()
Initialize the Deway SDK. Must be called before using other methods.
Deway.init(config: DewayConfig): void
Parameters:
config(DewayConfig): Configuration object
Example:
Deway.init({
appKey: 'your-app-key'
});
See Configuration for all available options.
Deway.identify()
Associate a user ID with the current session for personalized experiences.
Deway.identify(userId: string): void
Parameters:
userId(string): Unique identifier for the user
Example:
// After user login
if (user?.id) {
Deway.identify(user.id);
}
Best Practices:
- Call after successful authentication
- Use consistent user IDs across sessions
- Don't use PII (email, name) as the user ID if possible
- Use the same ID format as your analytics tools for cross-referencing
Deway.showBubble()
Display the AI chat bubble.
Deway.showBubble(config?: BubbleConfig): void
Parameters:
config(BubbleConfig, optional): Bubble appearance configuration
Example:
// Show with default config
Deway.showBubble();
// Show with custom config
Deway.showBubble({
position: 'bottom-right',
primaryColor: '#000000'
});
Deway.hideBubble()
Hide the AI chat bubble.
Deway.hideBubble(): void
Example:
Deway.hideBubble();
Deway.isBubbleVisible()
Check if the bubble is currently visible.
Deway.isBubbleVisible(): boolean
Returns:
boolean:trueif visible,falseotherwise
Example:
if (Deway.isBubbleVisible()) {
console.log('Bubble is visible');
}
Deway.destroy()
Clean up SDK resources and stop all tracking. Useful for SPA route changes or user logout.
Deway.destroy(): void
Example:
// On user logout
function handleLogout() {
Deway.destroy();
// ... rest of logout logic
}
What gets cleaned up:
- Event listeners
- WebSocket connections
- Timers and observers
- DOM elements (bubble, overlays)
Rise.track()
Manually track a custom event (optional - Deway auto-tracks most events).
Rise.track(eventName: string, properties?: Record<string, any>): void
Parameters:
eventName(string): Name of the eventproperties(object, optional): Additional event properties
Example:
Rise.track('feature_used', {
featureName: 'export',
format: 'csv'
});
Note: Deway automatically tracks most user interactions. Manual tracking is only needed for custom business events.
Rise.setUserProperties()
Set or update properties for the identified user.
Rise.setUserProperties(properties: Record<string, any>): void
Parameters:
properties(object): User properties to set
Example:
Rise.setUserProperties({
plan: 'pro',
company: 'Acme Inc',
role: 'admin'
});
Common use cases:
- Update subscription tier
- Set user role or permissions
- Track user preferences
- Store cohort membership
Complete Example
import Deway from '@deway-ai/web-sdk';
// Initialize on app load
Deway.init({
appKey: 'your-app-key',
isDevelopment: process.env.NODE_ENV === 'development'
});
// Identify user after login
function handleLogin(user) {
Deway.identify(user.id);
Rise.setUserProperties({
plan: user.subscription.plan,
role: user.role,
signupDate: user.createdAt
});
}
// Clean up on logout
function handleLogout() {
Deway.destroy();
}
// Manual event tracking (optional)
function handleExport(format) {
Rise.track('export_completed', {
format: format,
timestamp: new Date().toISOString()
});
}