Home > widget-integration > RecommendationAPI > addPageParam

RecommendationAPI.addPageParam() method

Adds page-specific parameter to enhance recommendation targeting.

This method injects the current page context into recommendation requests, allowing the API to optimize recommendations based on where the user is browsing (product page, cart, checkout, etc.).

Signature:

protected addPageParam<P extends Record<string, unknown>>(params: P): P & {
		pg: string;
	};

Parameters

Parameter

Type

Description

params

P

Base parameters object to enhance with page information

Returns:

P & { pg: string; }

Enhanced parameters with pg field containing the page-specific value from , or empty string if page is unknown

Example

Override to add custom page detection logic:

protected addPageParam<P extends Record<string, unknown>>(params: P): P & { pg: string } {
  const enhanced = super.addPageParam(params);

  // Add custom page detection for SPA routing
  if (!enhanced.pg && window.location.hash.includes('#/custom')) {
    enhanced.pg = 'custom_page';
  }

  return enhanced;
}