Skip to main content

trackUserActivity

Record a user or guest activity event.

Description​

Records one activity event, such as a product view, a search or a cart action, for the authenticated user or the current guest. Resolves to true once the API accepts the event. The event is stored in the background on a best-effort basis, so true means accepted, not saved. If the API refuses the event (for example, an unknown type), it resolves to an IError, or throws when isShell is false.

.trackUserActivity(

);

Parameters schema​

Schema

body(required): ITrackActivity
Activity event to record.
example:

{ type: "product_view", productId: 12345 }

body.type(required): TUserActivityType
Activity event type.
example: "product_view"

body.productId: number
Product ID.
example: 12345

body.pageId: number
ID of the page, for page_view and category_view events.
example: 7

body.categoryId: number
Legacy field. Send the category page's ID in pageId instead.
example: 67

body.query: string
Search query (for type=search).
example: "iphone case"

body.meta: Record<string, unknown>
Arbitrary meta information (source block, A/B variant, scroll-depth).

Examples​

Minimal example​

const response = await UserActivity.trackUserActivity({
type: 'product_view',
productId: 12345,
});

Example with optional fields​

const response = await UserActivity.trackUserActivity({
type: 'search',
query: 'iphone case',
meta: { sourceBlock: 'header_search', variant: 'b' },
});

Example response​

true

Response schema​

Details

Schema: boolean boolean: boolean
true if the API accepted the event.
example: true