import { RampWidget } from '@nowramp/sdk';
const widget = new RampWidget({
apiKey: 'your_api_key',
projectId: 'your_project_id',
externalUserId: 'user_123',
containerId: 'widget-container',
environment: 'production', // or 'sandbox'
// Widget URL: https://widget.nowramp.com
});
// Lifecycle
widget.on('ready', () => hideLoader());
widget.on('close', () => hideModal());
widget.on('error', (e) => showError(e.message));
// Analytics
widget.on('stepChanged', ({ to, providerData }) => {
analytics.page(to);
// Track provider status changes
if (providerData?.status) {
analytics.track('Provider Status', {
step: to,
status: providerData.status,
});
}
});
widget.on('quoteGenerated', (q) => analytics.track('Quote', q));
widget.on('kycStarted', () => analytics.track('KYC Started'));
widget.on('orderCreated', (o) => analytics.track('Order Created', o));
// Provider progress
widget.on('stepChanged', ({ providerData }) => {
if (providerData?.progress !== undefined) {
updateProgressIndicator(providerData.progress);
}
});
// Conversions
widget.on('orderComplete', (order) => {
analytics.track('Purchase', {
value: order.sourceAmount,
currency: order.sourceCurrency,
});
showSuccess('Your crypto is on the way!');
});
widget.on('orderFailed', ({ error }) => {
showError('Order failed. Please try again.');
});
widget.mount();