Core API Reference

The Mtrix package provides a simple yet powerful API for integrating analytics and experimentation into your website.

Upon successful initialization, Mtrix will:

  1. Verify your organization and project IDs

  2. Set up enabled features based on configuration

  3. Begin collecting basic page data

  4. Record an initialization event

If your debug key set to true, you can check the initialization status in your browser console, where you should see:

Mtrix initialized: v1.1.0

Core Methods

mtrix.init(config)

Initializes the Mtrix SDK with configuration options.

mtrix.init({
  organizationId: 'org-123',
  projectId: 'proj-456',
  environment: 'production'
});

mtrix.trackEvent(eventName, properties)

Records a custom event with optional properties.

mtrix.trackEvent('ButtonClicked', {
  buttonId: 'signup-button',
  location: 'hero-section'
});

mtrix.getPageDetails(params)

Retrieves experiment configurations for a specific page and user.

If you're using server-side initialization, audience details must be provided by you. For details visit here.

const experiments = await mtrix.getPageDetails({
  location: '/checkout',
  userId: 'user-123',
  audience: [
    {
      audienceKey: 'country',
      value: 'CA'
    }
  ]
});

console.log(experiments);
{
  
}

mtrix.getPerformance()

Retrieves the current performance metrics collected.

const metrics = mtrix.getPerformance();
console.log('LCP:', metrics.LCP, 'CLS:', metrics.CLS);

Last updated