This page provides recommended practices for integrating the TwoCoin widget to ensure a secure, reliable, and user-friendly experience for your users.
Where you place the widget on your website can significantly impact user experience and conversion rates:
Optimize the loading and performance of the widget to provide a smooth user experience:
<!-- Lazy loading iframe example -->
<div class="widget-container">
<div class="loading-placeholder" id="widget-loading">
Loading cryptocurrency exchange...
</div>
<iframe
id="widget-iframe"
loading="lazy"
src="https://your-widget-domain.com/widget"
width="100%"
height="800px"
frameBorder="0"
onload="document.getElementById('widget-loading').style.display='none'">
</iframe>
</div>Ensure your widget integration works well on mobile devices:
Create a smooth and intuitive user experience:
Set sensible default values by pre-configuring the widget URL to make it easier for users to get started:
<!-- Pre-configure common values for your audience -->
<iframe
src="https://your-widget-domain.com/widget?fromCurrency=USD&toCurrency=BTC"
width="100%"
height="800px"
frameBorder="0">
</iframe>Implement robust error handling to guide users when things go wrong:
// Custom error handling
TwoCoin.on('error', function(error) {
console.error('Widget error:', error);
// Show a user-friendly error message
if (error.code === 'network_error') {
showErrorMessage('Connection issue detected. Please check your internet connection and try again.');
} else if (error.code === 'validation_error') {
showErrorMessage('Please check your input and try again.');
} else {
showErrorMessage('Something went wrong. Please try again or contact support.');
}
// Log error for monitoring
logErrorToMonitoring(error);
});Protect your users and your business with these security practices:
Always use HTTPS for your website. The widget will not function correctly on non-secure pages.
Never expose your API secret in client-side code. Use server-side endpoints for sensitive operations.
Always validate webhook signatures to ensure they come from TwoCoin.
Verify order details on your server before processing orders or updating statuses.
Track the performance of your integration:
// Example: Tracking widget events with Google Analytics
TwoCoin.on('orderCreated', function(order) {
if (typeof gtag === 'function') {
gtag('event', 'order_created', {
'event_category': 'TwoCoin Widget',
'event_label': order.orderId,
'value': order.sourceAmount
});
}
});
TwoCoin.on('orderCompleted', function(order) {
if (typeof gtag === 'function') {
gtag('event', 'order_completed', {
'event_category': 'TwoCoin Widget',
'event_label': order.orderId,
'value': order.sourceAmount
});
}
});Ensure a robust testing process before going live:
If you encounter any issues or have questions not addressed in this documentation, please contact our support team on Telegram at https://t.me/cs_2coin (@cs_2coin).