Home > widget-integration > RecommendationService > validateWidget

RecommendationService.validateWidget() method

Validates whether a widget should be rendered based on configuration and page context.

Performs comprehensive validation including: - Widget ID presence and format - Page type identification - Current page context matching - Widget configuration existence - Widget settings completeness - Template metadata availability

Signature:

validateWidget(payload: Partial<{
		widgetId?: string;
	}>): boolean;

Parameters

Parameter

Type

Description

payload

Partial<{ widgetId?: string; }>

Object containing the widget identifier. The widgetId should be a non-empty string that exists in the TAE configuration for the current page type.

Returns:

boolean

True if the widget passes all validation checks and should be rendered, false if any validation check fails (e.g., widget not configured, wrong page, missing settings).

Example

Basic widget validation:

if (this.validateWidget({ widgetId: 'homepage-recommendations-1' })) {
  const model = await this.getRecommendationModel('homepage-recommendations-1');
  await this.renderWidget(model);
}