Fetch Recently Viewed Products [Beta]

Fetch Products that have been recently viewed by a Shopper

🚧

Contact support for using Beta Shopper APIs.

swat.shopper.fetchRecentlyViewedProducts

This API retrieves the products that are recently viewed by a shopper. For logged-in shoppers, all recently viewed are retrieved, while for non-logged-in shoppers, all recently viewed actions associated with their session on the device are retrieved. By default, the API returns a maximum of 12 recently viewed products.

Definition

swat.shopper.fetchRecentlyViewedProducts(onSuccess, onError)

Example

Here's an example of how you can use this API to fetch the Recently Viewed products:

// Define success callback
let onSuccess = function(data) {
  // Successfully fetched the recently viewed products
  console.log("These are the products recently viewed products by the shopper : ", data.recentlyViewed);
}

// Define error callback
let onError = function(error) {
  // Error is an xhrObject
  console.log("Error while fetching the shopper activity ", error);
}

// Call `shopper.fetchRecentlyViewedProducts` function
swat.shopper.fetchRecentlyViewedProducts(onSuccess, onError);

API Parameters

ArgumentTypeDescription
onSuccessfunctionCalled when the Recently Viewed Products are fetched successfully.
onErrorfunctionCalled when there is an error while fetching Recently Viewed Products

Success Response

The success response contains by default, a maximum of 12 Recently Viewed products in the recentlyViewed key.

{
  "recentlyViewed": [
    {
      // Number of times the product is viewed
      "count": 28,
      // Product ID from the Platform
      "productId": 7096231231686,
      // Timestamp at which the product was viewed last time
      "lastViewedTime": 1709013095458,
      // Varaint ID form the Platform
      "variantId": 41254655393990,
      // Produc URL
      "productURL": "https://demo.swym.it/products/ceramic-oval-basin",
      // Timestamp of the latest order placed with the product after it was viewed
      "lastOrderTimestamp": 1708426159001,
      // ID of the variant that was ordered after the product was viewed
      "lastOrderedVariantId": 41254655393990,
      // ID of the latest order placed with the product after it was viewed
      "lastOrderId": 2849832
    }
  ]
}

Other References

Recently Viewed Fields

ArgumentTypeDescription
countnumberNumber of times the product is viewed
productIdnumberProduct ID from the Platform
lastViewedTimenumberLast viewed Timestamp in UTC
productURLstringProduct URL
variantIdnumberVariant ID from the Platform
lastOrderTimestampnumberTimestamp of the latest order placed with the product after it was viewed
lastOrderIdnumberID of the latest order placed with the product after it was viewed
lastOrderedVariantIdnumberID of the variant that was ordered after the product was viewed