Add the #DF24 Developer Keynote to your agenda. Join us in-person on 9/18 at 2:30 p.m. PT or on Salesforce+ at 5 p.m. PT for the must-see session built just for developers.

Shopper Context Best Practices

The Shopper Context API is essential for managing personalized shopping experiences on your storefront. It is designed to optimize interactions for both guest and registered users by setting context-specific attributes that enhance personalization and efficiency.

When setting shopper context, the API utilizes the USID derived from the SLAS token, ensuring a seamless and secure integration.

  • Always set shopper context information from your Backend for Frontend (BFF) using private clients. Do not use public clients for this purpose.
  • Include the siteId query parameter in all Shopper Context API requests (GET, PUT, PATCH, and DELETE).
  • Initial visit or login: Implement shopper context when a shopper logs in or initially visits the storefront, immediately after obtaining the SLAS (Shopper Login and Access Services) token.
  • Token refresh: For SLAS token refresh, reuse the existing USID to maintain continuity and prevent duplicate records. This is important due to the resources available to store shopper context data.
  • Session Management: Reset the context upon user login as logging out clears the existing shopper context.
  • Context lifetime: Shopper context records last 1 day for guest shoppers and 7 days for registered shoppers. Regular updates are crucial to keep the context current.
  • Quota limits: Be aware of the default quota limits for the number of shopper context records that can be created in a B2C Commerce instance:
    • 5000 records for non-Production instances.
    • 1 million for Production instances.
    • If you have a legitimate need to increase the limit in your Production instances, contact your Customer Success Manager or Account Executive.
  • Avoid Duplicates: Reuse USIDs and verify existing contexts before setting new ones.
  • Efficient resource use: Regularly update existing contexts to optimize the limited storage available.
  • Preferred timing for updates: Align context updates with token refresh events to ensure consistency and minimize redundant updates.
  • Update your API integrations to include the siteId query parameter in all requests to the Shopper Context API. The following example shows the updated request format:

Do not use Shopper Context when attributes like customer profiles and addresses are automatically assigned and evaluated.

  • Store personalization: At login, use the Shopper Context API to set the store ID in both the customerQualifier and assignment qualifier, ensuring tailored interactions per store.
  • Dynamic personalization: Utilize store IDs from the Shopper Context for personalized pricing and promotions during the session.
    • The store ID is retrieved from the context and stored in the session for future reference, for example: session.custom.storeId.
    • If dynamic customer groups are set for specific store IDs, it activates experiences assigned with the corresponding customer groups.
  • Pricebook and promotion triggers: Use shopper context to activate specific pricebooks and promotions. For example, setting the store ID to BOST1 might trigger the BOSPRICEBOOK and 10%OFFPROMOTION for that particular store. Subsequent product retrieval calls will return personalized responses based on these triggers.

Sorting Rules are not supported.