error Event

The error event is triggered when an error occurs on the site or app — such as failed API calls, broken forms, or failed transactions. Tracking these errors is crucial for debugging, UX improvement, and alerting systems.

The error model

This model outlines key metadata for identifying and responding to application errors.

Properties

  • Name
    event
    Type
    string
    Description

    Must be set to error.

  • Name
    error_type
    Type
    string
    Description

    Type or category of the error (e.g., validation, network, payment).

  • Name
    error_message
    Type
    string
    Description

    Human-readable error message (safe for logs).

  • Name
    user_id
    Type
    string
    Description

    ID of the user (if available).

  • Name
    session_id
    Type
    string
    Description

    Current session ID.

  • Name
    timestamp
    Type
    string
    Description

    ISO timestamp when the error occurred.

  • Name
    context
    Type
    object
    Description

    Optional — extra debugging metadata (e.g., component name, request ID).


Push event to the dataLayer

dataLayer.push example

dataLayer.push({
  event: 'error',
  error_type: 'network',
  error_message: 'Failed to fetch product list',
  user_id: 'user-567',
  session_id: 'session-123abc',
  timestamp: new Date().toISOString(),
  context: {
    endpoint: '/api/products',
    component: 'ProductGrid'
  }
});

Best Practices

  • Avoid pushing sensitive data in error_message.
  • Add useful metadata in context for debugging.
  • Consider pushing errors to analytics and monitoring tools in parallel.

Use Cases

The error event supports:

  • Frontend and backend monitoring
  • UX and form validation improvements
  • Alerting workflows
  • QA and regression testing insights

Was this page helpful?