Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • The Sanity ID for the live offers document, for the most part, will be feature-loyalty-offers-ui-singleton, however, some markets have drifted from this convention.

  • An offer is open only if it has the ruleset RequiresAuthentication = False. If the ruleset RequiresAuthentication is not present in the offer OR if the ruleset RequiresAuthentication = True, then the offer is closed and should only show for guests that are signed into the kiosk.

  • Sample query:

Code Block
languagegraphql
query getSanityOffers {
  LoyaltyOffersUI(id: "feature-loyalty-offers-ui-singleton") {
    # Available for all users.
    # You can use these to lookup assets from global.
    sortedSystemwideOffers {
      _id
      loyaltyEngineId
      name {
        enRaw
      }
      rules {
        # Returns the value of the AuthenticationRequired rule
        ... on RequiresAuthentication {
          requiresAuthentication
        }
      }  # Add more }rules as needed here (e.g. FirstOrderOnly, LoyaltyBetweenDates, etc)
      }
    }
    # These are config. offers (templates).
    # You should use these only to display content (images, names, etc).
    # You can use these to lookup assets from the actual Personalized offers.
    liveConfigOffers {
      _id
      loyaltyEngineId
      name {
        enRaw
      }
    }
  }
}

...

Code Block
{
  "data": {
    "loyaltyRewardsV2": [
      {
        "id": "3b5bdddc-c7c9-42d8-9332-b0c3f36c8e1c",
        "name": "Value Powerade Zero",
        "errors": null
      },
      {
        "id": "728aaedd-3234-4eae-89af-35cd5672adcb",
        "name": "Large Dr. Pepper",
        "errors": null
      },
      {
        "id": "480122d7-86ff-4db0-965c-7dbb72bb5179",
        "name": "Value Soft Drinks",
        "errors": null
      }
    ]
  }
}

 

Mapping loyalty offers between Sanity and the Loyalty Engine

After retrieving all the available offers from both sources, you need to map this data to get a complete list of offers available to the user. Below there is a simple example in JavaScript demonstrating how to perform this mapping:

Note

This example focuses on the basic data mapping process. It does not include logic related to offer rules, authentication requirements, or error handling. Each implementation should incorporate the necessary logic based on its specific needs.

Code Block
const { liveConfigOffers, sortedSystemwideOffers } = sanityOffers;
const { loyaltyOffersV2 } = loyaltyEngineOffers;

const allAvailableUserOffers = loyaltyOffersV2
  .map(loyaltyOffer => {
    let sanityOffer;

    if (loyaltyOffer.type === 'GLOBAL') {
      sanityOffer = sortedSystemwideOffers.find(
        offer => offer.loyaltyEngineId === loyaltyOffer.id
      );
    } else if (loyaltyOffer.type === 'PERSONALIZED') {
      sanityOffer = liveConfigOffers.find(
        offer => offer.loyaltyEngineId === loyaltyOffer.id
      );
    }

    if (sanityOffer) {
      return sanityOffer;
    }
  })
  .filter(offer => offer !== undefined);

In this example 💡:

  • sanityOffers contains the offers retrieved from Sanity, destructured into liveConfigOffers (personalized offer templates) and sortedSystemwideOffers (system-wide offers).

  • loyaltyEngineOffers contains the offers retrieved from the Loyalty Engine, specifically the loyaltyOffersV2 array.

  • allAvailableUserOffers contains all the available offers for the user.