Promo code claiming in Salesforce
A cool thing you can do in the Salesforce Marketing Cloud is offer your subscribers a unique promo code as part of a promotional email campaign.
-
15 February 2023
While working at White Stuff, I implemented a number of automated lifecycle campaign to improve engagement with the brand. The campaigns ranged from a birthday email to lapsed customers, with each campaign offering an incentive to purchase a product.
Each one of these campaigns included a unique code which had to be claimed by the customer.
The codes would be added into a date extension as available codes, which live claiming from the emails marking them unavailable. A customer would be designated a code via AMPscript and once it was claimed would be flagged as not longer being valid.
How to create promo code claiming
There is a function called ClaimRow that allows us to assign an identifier (Id, email address, SubscriberKey…) to a record in a Data Extension, if the record is currently unassigned.
To start, create a data extension and call it “PromoCodes”. Add the following fields:
Remember to make sure that ‘Nullable’ is ticked against “IsClaimed”, otherwise the code will not be read as claimed and will continue to be useable for customers.
After this, generate your own list of unique promo codes in Excel. All that is needed is a list of codes and a header called “PromoCode”.
Then, import your promos into the Data Extension with the import button. Make sure the Date Extensions looks like this when it’s imported:
Finally, add this AMPscript to your email. This code will try to find a promo row for the specific email address in the PromoCodes data extension. If it finds one, it’ll return the promo code. If not, it will claim an unclaimed code and associate it with the email address. That promo code will then be marked as claimed in the data extension and be taken out of future opens.
If the email address has already claimed the code, then you will see a message relating to that appear instead.
%%[
var @promoRow, @email, @promoCode
set @email= AttributeValue("EmailAddress")
set @promoRow = ClaimRow("PromoCodes","IsClaimed", "EmailAddress", @email)
if empty(@promoRow) then
RaiseError("No promo code", false)
else
SET @promoCode = Field(@promoRow,"promoCode")
endif
]%%
Your promo code is: %%=v(@promoCode)=%%
Run the code and check the data extension once a code has been claimed. If it’s been successful, then the data extension should resemble the below: