Event Tracking
Last updated
Last updated
mtrix.trackEvent('CTAClicked');mtrix.trackEvent('ProductViewed', {
productId: '12345',
productName: 'Wireless Headphones',
category: 'Electronics',
price: 99.99,
currency: 'USD'
});// For manual tracking
mtrix.trackEvent('PageView', {
category: 'Blog',
author: 'John Doe'
});mtrix.trackEvent('Purchase', {
transactionId: 'unique-transaction-id', // required
revenue: '129.99' // required
});mtrix.init({
// ... other config
options: {
events: {
validateEvent: (eventName, properties) => {
// Don't track events with missing required properties
if (eventName === 'Purchase' && !properties.transactionId) {
console.warn('Purchase event missing orderId');
return false;
}
return true;
}
}
}
});mtrix.init({
// ... other config
options: {
debug: true
}
});
// Now events will be logged to console
mtrix.trackEvent('DebugEvent', { test: true });
// Console: [Mtrix] Event tracked: DebugEvent { test: true }