> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mailglyph.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Events

> Track events and list event names with the MailGlyph Node.js SDK.

Use a **public key** for tracking events, and a **secret key** for listing event names.

## Track an event (`events.track`)

```ts theme={null}
import MailGlyph from 'mailglyph';

const tracker = new MailGlyph(process.env.MAILGLYPH_PUBLIC_KEY as string);

const result = await tracker.events.track({
  email: 'user@example.com',
  event: 'purchase',
  subscribed: true,
  data: {
    product: 'premium',
    amount: 99
  }
});

console.log(result.success, result.data.timestamp);
```

## List event names (`events.listNames`)

```ts theme={null}
import MailGlyph from 'mailglyph';

const client = new MailGlyph(process.env.MAILGLYPH_SECRET_KEY as string);

const { eventNames } = await client.events.listNames();

console.log(eventNames);
```

## List event names with alias (`events.getNames`)

`getNames()` is an alias for `listNames()`:

```ts theme={null}
const { eventNames } = await client.events.getNames();

console.log(eventNames);
```

See endpoint details in the [Track event API reference](https://docs.mailglyph.com/api-reference/public-api/trackEvent.md) and [List event names API reference](https://docs.mailglyph.com/api-reference/events/listEventNames.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.