Quick start

Export events, sessions, and users from a workspace.

The Export API client provides three methods to export data from your workspace. Each method supports pagination and optional time-based filtering.

Install the client

Install the client using your preferred package manager:

npm
npm install @croct/export

Export events

Here is how to export event data from your workspace:

Export events
123456789101112131415161718192021222324
import {Configuration, ExportApi} from '@croct/export';
async function exportEvents(): Promise<void> {  const api = new ExportApi(    new Configuration({      apiKey: '<API KEY>'    })  );
  let cursor: string | undefined = undefined;  let running = true;
  while (running) {    const {data: {items: events, nextCursor}} = await api.exportEvents({      pageSize: 100,      cursor: cursor,    });
    console.log(events);
    cursor = nextCursor;    running = events.length > 0;  }}

You can filter events by type using the events parameter:

Filter events by type
12345678910
import {Configuration, EventType, ExportApi} from '@croct/export';
const {data: {items: events}} = await api.exportEvents({  pageSize: 100,  events: [    EventType.PRODUCT_VIEWED,    EventType.CHECKOUT_STARTED,    EventType.ORDER_PLACED,  ],});

See the API reference for a complete list of event types.

Export sessions

Here is how to export session data from your workspace:

Export sessions
123456789101112131415161718192021222324
import {Configuration, ExportApi} from '@croct/export';
async function exportSessions(): Promise<void> {  const api = new ExportApi(    new Configuration({      apiKey: '<API KEY>'    })  );
  let cursor: string | undefined = undefined;  let running = true;
  while (running) {    const {data: {items: sessions, nextCursor}} = await api.exportSessions({      pageSize: 100,      cursor: cursor,    });
    console.log(sessions);
    cursor = nextCursor;    running = sessions.length > 0;  }}

Export users

Here is how to export user data from your workspace:

Export users
123456789101112131415161718192021222324
import {Configuration, ExportApi} from '@croct/export';
async function exportUsers(): Promise<void> {  const api = new ExportApi(    new Configuration({      apiKey: '<API KEY>'    })  );
  let cursor: string | undefined = undefined;  let running = true;
  while (running) {    const {data: {items: users, nextCursor}} = await api.exportUsers({      pageSize: 100,      cursor: cursor,    });
    console.log(users);
    cursor = nextCursor;    running = users.length > 0;  }}

You can specify the start and end parameters to define the time range for the data you want to export. For example, to export events from the last 24 hours:

Time-based filtering
1234567891011
const today = new Date();today.setHours(0, 0, 0, 0);
const yesterday = new Date(today.getTime());yesterday.setDate(today.getDate() - 1);
const {data: {items: events}} = await api.exportEvents({  pageSize: 100,  start: yesterday.getTime(),  end: today.getTime(),});