trackUserActivity
Record a user or guest activity event.
Description
This method records a single activity event for the current authorized user or guest (for example a product view, a search, or a cart action). It returns a Promise that resolves to true if the event was recorded, or an IError object if there was an issue.
UserActivity.trackUserActivity(
body*,
body.type*,
body.productId,
body.pageId,
body.categoryId,
body.query,
body.meta
);
Parameters schema
Schema
body(required): ITrackActivity
Activity event body. Example: { type: "product_view", productId: 12345 }
body.type(required): TUserActivityType
Activity event type. One of: "product_view", "page_view", "category_view", "search", "product_add_to_cart", "product_remove_from_cart", "product_add_to_wishlist", "product_remove_from_wishlist", "product_purchase", "product_rating".
example: "product_view"
body.productId: number
Product identifier.
example: 12345
body.pageId: number
Page identifier (for page_view, category_view).
example: 7
body.categoryId: number
Legacy category identifier.
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 attributes
const response = await UserActivity.trackUserActivity({
type: 'search',
query: 'iphone case',
meta: { sourceBlock: 'header_search', variant: 'b' },
});
Example response
true
Response schema
Schema: boolean
boolean: boolean
Returns true if the event was recorded.
example: true