Home > widget-integration > RecommendationAnalytic > storeRecommendationWidgetTrackingData
RecommendationAnalytic.storeRecommendationWidgetTrackingData() method
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.
Signature:
storeRecommendationWidgetTrackingData(data: RecommendationWidgetTrackingData): void;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
data |
The recommendation widget tracking data to persist. Must include a valid widget ID (wid). Optional fields (rid, rt) can be included for additional tracking context. |
Returns:
void
Remarks
This method performs the following operations: 1. Generates a unique storage key using the widget ID 2. Serializes the tracking data to JSON 3. Attempts to store in localStorage 4. Delegates to error handler if storage fails
The method is designed to be non-blocking - storage failures won't prevent widget functionality from working. This ensures optimal widget performance even when localStorage is unavailable.
Example 1
Store basic tracking data for a recommendation widget:
analytic.storeRecommendationWidgetTrackingData({
wid: 'homepage-recommendations',
rid: 'rec-abc123',
rt: 'frequently-bought-together'
});
Example 2
Store minimal tracking data (only widget ID required):
analytic.storeRecommendationWidgetTrackingData({
wid: 'cart-page-upsells'
});