LogoLogo
  • Overview
  • Key Features
  • Getting Started
    • Installation
    • Quick Start Guide
    • Configuration Options
    • Authentication
  • NPM Package
    • Installation
    • Core API Reference
    • Event Tracking
    • Experimentation
    • Performance Monitoring
    • Session Recording
    • Error Tracking
    • Advanced Configuration
  • A/B Testing & Experimentation
    • Creating Experiments
    • Targeting Users
    • Measuring Results
    • Statistics & Significance
    • Best Practices
  • Analytics Dashboard
    • Overview
    • User Journey Analysis
    • Conversion Funnels
    • Custom Reports
  • Session Recording
    • Privacy Considerations
    • Viewing Recordings
    • Filtering & Searching
    • Heatmaps
  • Performance Monitoring
    • Core Web Vitals
  • User Management
    • Roles & Permissions
    • Team Collaboration
    • Access Controls
    • Audit Logs
  • Troubleshooting
    • Common Issues
    • Debugging Tools
    • Error Reference
  • Appendix
    • Glossary
    • API Status Codes
    • Migration Guides
    • Release Notes
    • Roadmap
Powered by GitBook
On this page
  1. NPM Package

Event Tracking

PreviousCore API ReferenceNextExperimentation

Last updated 1 month ago

Event tracking is the foundation of analytics in Mtrix. Events represent user actions, system occurrences, or any custom activities you want to monitor.

Add alt text and captions to your images

Basic Event Tracking

To track a simple event:

mtrix.trackEvent('CTAClicked');

Events with Properties

Events can include additional properties to provide context:

mtrix.trackEvent('ProductViewed', {
    productId: '12345',
    productName: 'Wireless Headphones',
    category: 'Electronics', 
    price: 99.99,
    currency: 'USD'
});

Standard Events

If you're not using Mtrix as your infrastructure, you need to track events manually. Only the Page View event will fire automatically on every history change --you can opt-out automatic event capturing on the initialization stage.

Page Views (*required)

// For manual tracking
mtrix.trackEvent('PageView', {
  category: 'Blog',
  author: 'John Doe'
});

Purchase Event (*required)

Purchase event is the main conversion event. It must fire whenever your experiment reaches its goal. Required field listed below:

mtrix.trackEvent('Purchase', {
  transactionId: 'unique-transaction-id', // required
  revenue: '129.99' // required
});

Customers who uses Mtrix as their infrastructure will receive the below events out-of-the box:

  1. AddToCart

  2. BeginCheckout

  3. CompleteCheckout

  4. Purchase

  5. Refund

Custom Event Validation

You can add custom validation logic before sending events:

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;
      }
    }
  }
});

Debugging Events

During development, you can enable debug mode to see detailed logs:

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 }