This event is triggered when an eligible referred customer clicks a referral link. This is often helpful if you are implementing a custom referred customer user experience. The event is passed the coupon code the customer earned.

function handleReferredCustomerCouponCode(couponCode) {
  // do whatever you want with the coupon code
  // show in popup, tab, add to checkout, etc
}

// handle the generation of the coupon code
$(document).on("swell:referred:customer:discount", function(event,couponCode) {
  // one common strategy is to save it in localStorage so that it's available on every page load if you need to display or use it.
  localStorage.setItem("swell-referred-customer-coupon-code", couponCode);
  handleReferredCustomerCouponCode(couponCode);
});

// on page load, use previously saved coupon code if one exists
$(document).ready(function() {
  var swellReferredCustomerCouponCode = localStorage.getItem(
    "swell-referred-customer-coupon-code"
  );
  if (swellReferredCustomerCouponCode) {
    handleReferredCustomerCouponCode(swellReferredCustomerCouponCode);
  }
});