top of page

June 30, 2020 - Esha Garg 

  • Twitter

AMPscript Basics: Getting Started with AMPscript
Part 2

Speakers: Genna Matson and Zuzanna Jarczynska

Scenario
 

Our company has a loyalty program where our customers get points towards rewards based on specific items purchased.

There are two purchase categories and when a threshold is met on a category subscribers are issued a coupon code, which they have to claim on a landing page.

The prompt to go to the coupon claim page is on display in a weekly email sent to update subscribers on their current point levels.

Image from iOS (14).jpg

The process to accomplish this scenario is:

  • Create two Data Extensions (Subscribers and Coupons)

  • New HTML email message (Header and Body)

  • Create a Cloud Page

  • Send an email with appropriate details and check for the coupon code to appear

Looking for AmpScript feature guide ? Check This

Let's get started with creating two separate Data Extensions, Subsribers and Coupons. Now starting with Subscribers DE, it would be a sendable data extension. It would capture the first name, last name, email as subscriber key (primary key), and reward tier 1, reward tier 2.


Wondering what is this reward tier exactly?
It would capture the points for the particular subscriber to be eligible to retrieve the coupon. So if it has 10 or more points it can only claim the coupon as per the scenario.


Now talking about the coupon data extension, it will capture:
Coupon Tier - reward tier1 or reward tier 2 
Coupon Code - as primary key, which would contain all coupon codes

isClaimed - to check whether it is already claimed once or not 

SubscriberKey - used as a unique identifier as email

Coupon Expiry - date of the expiry of the coupon 

Image from iOS (1).png
Image from iOS (2).png
Image from iOS (3).png

Here, two environments were used as code editors. One was Sublime text -> Amscript Highlighter and the other one was Visual Studio Code -> Amscript Highlighter.

 

So, Sublime text was used to create the code for header and body content and Visual Studio Code for cloud page creation.

Let's get started with the creation of new email message

SUBJECT: %%=v(@subjectLine)=%%

TEMPLATE: ampscriptBasics_template.html

Image from iOS (17).jpg

INIT: amscript_init.html

Image from iOS (16).jpg

CONTENT: ampscriptBasics_staticContent.html

Image from iOS (18).jpg

BODY: amscript_content.html

Image from iOS (15).jpg

Confused about these long codes?
Not to worry, look here! First, template.html code is to create a saved email message. Second is the static content where we define the header(pre-header and view online) and the footer(Unsubscribe and Privacy Policy). The third is the init.html code where we define all the functionalities of the scenario like capturing email as subscriber key, calculation of reward points, remainder reward points for claiming the coupon, and assigning the proper tier#. The fourth one declares everything that you need in the body of the email message. It should first retrieve the reward points and accordingly give the coupon if it is greater than 9 or say equal to 10. It shall also calculate the remaining points needed to retrieve the coupon. Now that we have two tiers, tier1 and tier2. It shall count separately for both of them. Suppose, it does not have any reward points, it shall show up "You do not have any reward points for tier#". With this, it defines properly what we need over the cloud page.
Hey, where is the Cloud Page id?
That means we need to create one cloud page to come up as a landing page and include the id in our body Html. Let's gear up for the same now.

CLOUD PAGE: couponCloudPage.amp

Image from iOS (19).jpg

Here we go with the cloud page code where we check for an email not equal to null and the coupon is not yet claimed. So, it runs like it will show up the coupon code on the next landing page and give the expiry date as more than 1 month from now. What if we have visited the page once? Seems like we claimed the coupon, Isn't it? So yes, the next time we open this page it will show that "You have already claimed the coupon code: XXXXX"

Does it seem interesting? Check out for the result screenshots below.

RESULT:

Image from iOS (20).jpg

Coupon Code: XXXXX
Expiry Date: 7/30/2020

If the above code is viewed once, it would be considered, isClaimed = TRUE and the below message would occur on the second click of the same claim code link

You have already claimed the coupon code: XXXXX

Hurray, we did it. It was so cool, right? We can get the particular points needed to get the coupon in the email message and also if we are having points greater than 9, we can easily retrieve the coupon code as well. Simple steps with only two data extensions and just a fabulous scenario accomplished.

bottom of page