Skip to content

Meta Schema ​

Meta rules enable you to extend the events schema. You can define optional or required meta fields for events to include under their "meta".

Configuration ​

Meta Rule ​

FieldTypeRequiredDescription
namestringyesProperty name
descriptionstringnoProperty context description
typestring, string[], boolean, Boolean[], number, number[], oneOfyesExpected TypeScript type
defaultValueanynoDefault value to use if one is not provided
optionalbooleannoMark property as optional
privatebooleannoPrivate fields won't be exposed to the tracker

Example ​

Here are example meta rules -

yaml
meta:
  - name: Class
    description: The environment where the event was triggered
    type:
      - View
      - Interaction
      - Usage
      - Activation
      - Error

  - name: Version
    description: The version of the application
    type: string
    defaultValue: '1.0'

With these meta rules, events can be defined as such -

events:
  page_view:
    name: Page View
    description: Triggered when a user views a page.
    properties:
      - name: Page Name
        description: The name of the page that was viewed.
        type: string
    meta:
      Class: View
      Version: 2.0

  add_user:
    name: Add User
    description: Triggered when an admin adds a user to their team. This requires a paid plan.
    properties:
      - name: Role
        description: The role of the user that was added.
        type:
          - admin
          - member
    meta:
      Class: Interaction

Non-private meta fields will be exposed to the tracker via the "meta" arg.

typescript
import { createAnalyticsTracker } from 'voltage-schema';
import { AnalyticsTracker, TrackerEvents, trackingConfig } from './__analytics_generated__/analytics';

const tracker = createAnalyticsTracker<TrackerEvents>(trackingConfig, {
  onEventTracked: (eventName, { properties, groups, meta }) => {
    // Send to Amplitude
    amplitude.getInstance().logEvent(eventName, {
      ...properties,
      ...meta,
      ...groups.User,
    });
  }
});

// Track an event
tracker.track('page_view', {
  "Page Name": 'Home'
});