Quick start

Export events, sessions, and users from a workspace.

The Export API client lets you export events, sessions, and users from your workspace in bulk, or individually by their ID. The bulk methods support 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;  }}

Time window filtering

You can specify the start and end parameters to define the time range for the events and sessions 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(),});

Export an event by ID

Here is how to export a single event by its ID:

Export an event by ID
123456789101112131415
import {Configuration, ExportApi} from '@croct/export';
async function getEvent(): Promise<void> {  const api = new ExportApi(    new Configuration({      apiKey: '<API KEY>'    })  );
  const {data: {metadata, event}} = await api.exportEventById({    eventId: '924f6c8f-3b5b-47ea-b483-25a0506dc436',  });
  console.log(event);}

Export a session by ID

Here is how to export a single session by its ID:

Export a session by ID
123456789101112131415
import {Configuration, ExportApi} from '@croct/export';
async function getSession(): Promise<void> {  const api = new ExportApi(    new Configuration({      apiKey: '<API KEY>'    })  );
  const {data: session} = await api.exportSessionById({    sessionId: '916c8d26-053d-4ce8-86c6-3c98b4185921',  });
  console.log(session);}

Export a user by ID

Here is how to export a single user by its ID:

Export a user by ID
123456789101112131415
import {Configuration, ExportApi} from '@croct/export';
async function getUser(): Promise<void> {  const api = new ExportApi(    new Configuration({      apiKey: '<API KEY>'    })  );
  const {data: user} = await api.exportUserById({    userId: '6d5f1fe8-3f21-4bce-9afb-e1d11b610674',  });
  console.log(user);}