User Consent Updated

An event that fires when the shopper updates consent.

Description

The onUserConsentUpdated listener fires when the shopper updates consent in the app.

The callback receives data. Each consent statement is a key, and the checkbox state is the boolean value. data.phone is the phone number entered on the same form, when the shopper provided one.

Statement keys are the copy shown on the consent form. They are not a fixed set.

This event does not update Superfans.variables. Read the answers from data.

Function Signature

Superfans.listeners.onUserConsentUpdated(function (data) {
  const acceptedTerms = data["I have read and accept the Terms of Service and Privacy Policy."];
  const phone = data.phone;
});
ParameterTypeRequiredDescription
dataObjectYesConsent answers. Statement text is the key and the checkbox state is the boolean value. phone is a string when the shopper entered one.

Example Usage

Superfans.listeners.onUserConsentUpdated(function (data) {
  const acceptedTerms = data["I have read and accept the Terms of Service and Privacy Policy."];
  const wantsOffers = data["I would like to receive offers and updates by email and SMS."];
  const phone = data.phone;

  if (acceptedTerms) {
    console.log("Terms accepted", phone || "");
  }
});

Best Practices

  1. Read the payload from the callback. This event does not write into Superfans.variables.
  2. Match statement keys to the exact copy shown on the consent form.
  3. Treat phone as optional. It is present only when the shopper entered a number.
  4. Use the event to sync marketing consent, or to gate a feature that depends on acceptance.

Caveats

  1. The event fires when consent changes, not on page load.
  2. There is no replay. A block that subscribes after the shopper submits consent does not receive the last answers.
  3. Keys are not stable identifiers. A copy change on the form changes the key.
  4. phone is a string on the same object as the boolean answers. Do not assume every value is a boolean.

Did this page help you?