monetization.openTrackingSession

API reference for the monetization.openTrackingSession method.

This API is only available to apps that have been accepted into the Premium Apps Program(opens in a new tab or window).

Starts a new tracking session for a billable action or resumes an existing one.

Usage

Start a tracking session for a billable action

import { auth } from '@canva/user';
const session = await auth.monetization.openTrackingSession({
action: 'MY_BILLABLE_ACTION'
});
try {
// Perform billable action
} finally {
// Always close the session when done
await session.close();
}
TYPESCRIPT

Resume a tracking session for a billable action

import { auth } from '@canva/user';
const session = await auth.monetization.openTrackingSession({
id: 'EXISTING_SESSION_ID'
});
try {
// Continue billable action
} finally {
await session.close();
}
TYPESCRIPT

Parameters

optsOpenTrackingSessionOptions
Required

Options to either start a new session or resume an existing session.

  • action: The billable action to be tracked (if starting a new session).
  • id: The ID of an existing session to resume (if resuming a session).
actionBillableAction
Sometimes required

Represents the possible billable actions that can be tracked.

Available values:

  • "modify_image"
  • "modify_video"
  • "modify_audio"
  • "modify_text"
  • "import_image"
  • "import_video"
  • "import_audio"
  • "import_text"
  • "generate_image"
  • "generate_video"
  • "generate_audio"
  • "generate_text"
idnever
Sometimes required

Returns

An object containing the session's unique id and a method to close the session. This is a Promise that resolves with the following object:

idTrackingId

Unique identifier for tracking sessions associated with billable actions.

closeTrackingSessionfunction

Returns

Promise<void>