Analytics & Event Tracking
Integration with analytics systems and user action tracking in the virtual try-on widget
Analytics & Event Tracking
The virtual try-on widget allows flexible analytics collection and user action tracking at two levels:
- Client-side (Frontend): using
onSuccessandonClosecallback functions to send goals to Yandex Metrica, Google Analytics, or social media pixels. - Server-side (Backend): using the
callbackDataparameter to pass service data to your own analytics system or CRM via Webhook.
1. Client-side Analytics (Yandex Metrica, Google Analytics)
You can pass handler functions to the fitting('create', ...) method:
onSuccess(data)— called when the try-on completes successfully (when the result is displayed to the user).onClose()— called when the user closes the modal window (via the close button or clicking outside the window).
Integration Example:
window.fitting('create', {
targetElementId: 'widget-container',
// ... your product parameters
// 1. Successful try-on generation
onSuccess: function(result) {
console.log('Try-on generated successfully:', result);
// Example: Send goal to Yandex Metrica
if (typeof ym !== 'undefined') {
ym(XXXXXX, 'reachGoal', 'tryon_success');
}
// Example: Send event to Google Analytics (GA4)
if (typeof gtag !== 'undefined') {
gtag('event', 'tryon_completed', {
event_category: 'Virtual Try-On',
item_name: 'Classic Denim Jacket'
});
}
},
// 2. Modal window closed
onClose: function() {
console.log('User closed the try-on widget');
// Send event to Yandex Metrica
if (typeof ym !== 'undefined') {
ym(XXXXXX, 'reachGoal', 'tryon_closed');
}
}
});