Home > widget-integration > RecommendationWidgetController > handleEmptyRecommendation
RecommendationWidgetController.handleEmptyRecommendation() method
Handles the case when recommendation data is empty or has no products.
By default, removes the widget element from the DOM and stops observing. Override this method to customize empty state behavior, such as showing a fallback message, displaying alternative content, or tracking empty states.
Signature:
protected handleEmptyRecommendation(parent: HTMLElement, unobserve: () => void): void;
Parameters
| 
 Parameter  | 
 Type  | 
 Description  | 
|---|---|---|
| 
 parent  | 
 HTMLElement  | 
 The parent HTML element containing the widget  | 
| 
 unobserve  | 
 () => void  | 
 Callback function to stop observing the element  | 
Returns:
void
Example 1
Override to show fallback content instead of removing:
protected handleEmptyRecommendation(parent, unobserve) {
  parent.innerHTML = `
    <div class="no-recommendations">
      <p>Check back soon for personalized recommendations!</p>
    </div>
  `;
  unobserve();
}
Example 2
Override to track empty states for analytics:
protected handleEmptyRecommendation(parent, unobserve) {
  this.analytics.track('empty_recommendations', {
    widgetId: this.currentWidgetId,
    customerId: this.customer?.id
  });
  super.handleEmptyRecommendation(parent, unobserve);
}