Business Challenge
An entertainment company runs a promotion every week. Within each promotion there are cash bonuses offered to different groups of customers. As the cash bonus varies from $50 to $1000, the client creates duplicate promotions where the only difference is the dollar value in the promo description.
Can we make promotion descriptions dynamic based on a user profile object value? Then we would only need to create one promotion instead of five, which would save us a lot of time.
We will need to reference different generosity bands from time to time. Can we choose a band at the campaign level?
Personalisation Solution
I optimised the client’s server-side manual promotion selector template to make the promotion dynamic at a 1:1 user level.
Step 1: Add a drop down selector to the template with options that match the profile object fields.
@title("Band Selector")
@subtitle("Generosity band from the user profile object GenerosityBands.")
@options([
{ label: "band1"},
{ label: "band2"},
{ label: "band3"},
{ label: "band4"},
{ label: "band5"}
])
bandSelector:string = { label: "band1"}
Step 2: Retrieve the selected generosity band and cross-reference it with the user’s profile object value for that band.
const selectedBand:string = this.bandSelector.label;
const userBandValue = context.user.profileObjects.GenerosityBands.GenerosityBands.attributes[selectedBand].value;
Step 3: Replace the dollar value in the promotion description with the user’s band value.
const promotion: Promotion = context.services.catalog.findItem("Promotion", this.selectedPromo.id) as Promotion;
let promoDescription: string = promotion?.attributes?.PromoDescription?.value ? promotion.attributes.PromoDescription.value as string : "";
promoDescription = promoDescription.replace("$value$","$"+userBandValue);