Home > widget-integration > RecommendationAnalytic
RecommendationAnalytic class
Service for handling recommendation widget analytics and tracking data storage.
This service manages the persistence of recommendation widget tracking data to localStorage, enabling analytics and tracking of user interactions with recommendation widgets. It provides customizable storage key generation and error handling that can be extended by Technical Support teams for shop-specific requirements.
Signature:
export declare class RecommendationAnalytic 
Remarks
The service uses localStorage for persistence, which has browser-specific limitations: - Storage quota varies by browser (typically 5-10MB) - May be unavailable in private browsing mode - Can be cleared by users at any time
Technical Support teams can extend this service to: - Customize storage key prefixes for multi-widget scenarios - Implement alternative storage mechanisms (sessionStorage, IndexedDB) - Add shop-specific error handling and fallback strategies - Integrate with custom analytics platforms
Example 1
Basic usage in widget code:
const analytic = new RecommendationAnalytic();
analytic.storeRecommendationWidgetTrackingData({
  wid: 'homepage-recs',
  rid: 'rec-12345',
  rt: 'similar-products'
});
Example 2
Extend to use custom storage prefix for multi-shop setup:
window.boostWidgetIntegration.extend('RecommendationAnalytic', (RecommendationAnalytic) => {
  return class CustomRecommendationAnalytic extends RecommendationAnalytic {
    protected getStorageKeyPrefix() {
      // Use shop domain in prefix to avoid conflicts
      return `${window.Shopify.shop}-boostSdRecommend`;
    }
  };
});
Example 3
Extend to implement fallback storage strategy:
window.boostWidgetIntegration.extend('RecommendationAnalytic', (RecommendationAnalytic) => {
  return class CustomRecommendationAnalytic extends RecommendationAnalytic {
    protected handleStorageError(error, data) {
      // Try sessionStorage as fallback
      try {
        const key = this.generateStorageKey(data.wid);
        sessionStorage.setItem(key, JSON.stringify(data));
      } catch (fallbackError) {
        // Send to custom analytics endpoint as last resort
        this.sendToAnalyticsAPI(data);
      }
    }
  };
});
Methods
| 
 Method  | 
 Modifiers  | 
 Description  | 
|---|---|---|
| 
 Generates a unique storage key for a recommendation widget. Combines the storage key prefix with the widget ID to create a unique localStorage key for storing widget tracking data. This ensures each widget's tracking data is stored separately and can be retrieved independently.  | ||
| 
 
  | 
 Gets the storage key prefix for recommendation widget tracking data. This method returns the base prefix used when generating localStorage keys for recommendation widgets. Override this method to customize the prefix for specific shop requirements, such as multi-shop setups or namespacing strategies.  | |
| 
 
  | 
 Handles errors that occur when storing recommendation tracking data to localStorage. This method is called when localStorage operations fail, providing an extension point for custom error handling strategies. Common failure scenarios include storage quota exceeded, private browsing mode restrictions, or localStorage being disabled. Override this method to implement shop-specific error handling, fallback storage mechanisms, or integration with error tracking services.  | |
| 
 Stores recommendation widget tracking data to localStorage. Persists tracking information for a recommendation widget to localStorage for later retrieval and analytics processing. The data is serialized to JSON and stored under a widget-specific key. If storage fails, the error is handled through the extensible error handling mechanism. This method is lightweight and synchronous, with error handling that won't block widget rendering if storage fails.  |