SDK Overview
Use @usesophi/sophi-web-sdk to embed the Sophi assistant in your storefront and handle widget events in your application code.
Use @usesophi/sophi-web-sdk to embed the Sophi assistant in your storefront and handle widget events in your application code.
For storefront event tracking without the widget (page, product, basket, purchase, etc.), use the separate package @usesophi/sophi-web-object — see the Web Object documentation.
Keep script loading and consent management separate from widget configuration. If you use GTM, GTM should only load the SDK script after consent; initialization should stay in your app code.
Required for production
Every customer integration should include these three items:
- Handle
add_to_cartevent. - Handle
send_to_checkoutevent. - Call
widget.updateUserCart(cart)whenever host cart data changes.
Without these, cart synchronization and checkout handoff will be incomplete.
Security reminder
- Keep real keys and tokens out of docs, GTM tags, and static frontend bundles.
- Use placeholders such as
YOUR_SOPHI_API_KEY. - Keep sensitive values server-side when possible.
What this SDK provides
- Framework-agnostic widget initialization
- Browser script support via
window.SophiWebSDK - Typed events for commerce actions
- Runtime methods for user/cart updates and widget lifecycle
Public API surface
- Class:
SophiWidget - Init:
await widget.init(config) - Events:
ready,add_to_cart,add_to_favorite,send_to_checkout,error - Methods:
on,off,updateUserCart,sendToggleHistory,sendTextMessage,sendProductReply,openProductById,triggerProductReply,show,hide,isReady,destroy
Step-by-step integration path
- Access widget object from
window(if script/GTM mode) or npm import. - Initialize widget.
- Wire required events (
add_to_cart,send_to_checkout). - Sync cart via
updateUserCart. - Add advanced methods (
sendToggleHistory,sendProductReply,triggerProductReply) only if needed.
Recommended reading order:
- GTM Integration for loading and troubleshooting script/runtime errors
- Events for required event handlers
- Methods for required cart sync and advanced controls
- Framework guides for copy-paste React/Angular examples (basic and advanced)
Documentation map
Installation
Install the SDK from npm.
GTM Integration
Load the SDK via GTM after consent and initialize in app code.
Initialization
Configure `SophiWidget` safely and correctly.
Events
Listen and respond to widget events in your app.
Methods
Runtime methods and lifecycle operations.
Security Best Practices
Prevent accidental secret exposure and unsafe integration.