Showing different images to customers in different Geographies using AMPscript in SFMC

Ujjwal AMPscript, SFMC Leave a Comment

You are required to send out a marketing email to a list of customers living in different states of Canada. Now there is an offer that is only available to customers living in particular states. In this scenario, you will have to make this offer element dynamic, so that it only appears to customers based out of these states.

This can be achieved using the Substring function of AMPscript if you have postal code information available for each customer.

Substring function documentation: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/Substring.htm

Let us assume, the sendable data extension has a field Postal_Code which contains postal code information for each customer.

Code sample 1:
We have an offer that is only available in Manitoba and Quebec. We will use AMPscript to make the offer image appear if the Postal Code is either in Manitoba or Quebec.

For Manitoba, Postal Codes start with R
For Quebec, Postal Codes can start with G, H or J

%%[ IF Substring(Postal_Code,1,1) == "R" OR Substring(Postal_Code,1,1) == "G" OR Substring(Postal_Code,1,1) == "H" OR Substring(Postal_Code,1,1) == "J" THEN ]%%

<table><tr><td>The dynamic element supposed to appear for these customers</tr></td></table>

%%[ ENDIF ]%%

Code sample 2:
We have an offer that is available across the country except for Ontario. Ontario Postal Codes can start with either K, L, M, N or P. We can use the Substring function to show the offer element only if the postal code does not start with K, L, M, N or P.

%%[ IF Substring(Postal_Code,1,1) != 'K' AND Substring(Postal_Code,1,1) != 'L' AND Substring(Postal_Code,1,1) != 'M' AND Substring(Postal_Code,1,1) != 'N' AND Substring(Postal_Code,1,1) != 'P' THEN ]%%

<table><tr><td>The dynamic element supposed to appear for rest of the country except Ontario</td></tr></table>

%%[ ENDIF ]%%

Code sample 3:
You have three offers – One applicable to customers in Ontario, the second offer applicable to customers in Quebec and the third offer applies to customers in the Rest of Canada.

Here is how you will build this in an email:

%%[ IF Substring(Postal_Code,1,1) == 'K' OR Substring(Postal_Code,1,1) == 'L' OR Substring(Postal_Code,1,1) == 'M' OR Substring(Postal_Code,1,1) == 'N' OR Substring(Postal_Code,1,1) == 'P' THEN ]%%

<table><tr><td>Ontario offer</td></tr></table> 

%%[ ELSEIF Substring(Postal_Code,1,1) == 'G' OR Substring(Postal_Code,1,1) == 'H' OR Substring(Postal_Code,1,1) == 'J' THEN ]%%

<table> <tr><td>Quebec offer</td></tr></table>

%%[ELSE]%%

<table><tr> <td>Rest of Canada offer</td></tr></table>

%%[ ENDIF ]%% %%[ ENDIF ]%%

Creating a dynamic content that will appear for Targeted FSA’s

There can be another scenario where you have been provided FSA’s from different provinces and asked to show the offer content to customers living in those FSA’s. FSA is the first three letters of the Postal Code.

Code sample:

You have been provided with a list of FSA’s – B3J, B4E, C0A, C1B, C1E, E1G, E1H, E1J and E2J. The customers living in regions belonging to these FSA’s are eligible for an offer. In this case, also, we can leverage the same Substring function we have used in the above examples. In the above examples, we were looking for the first character of the postal code, in the case of an FSA, we will look for the first three characters.

%%[ SET fsa = Substring(postalCode,1,3)
IF @fsa == 'B3J' OR @fsa == 'B4E' OR @fsa == 'C0A'
OR @fsa == 'C1B' OR @fsa == 'C1E' OR @fsa == 'E1G'
OR @fsa == 'E1H' OR @fsa == 'E1J' OR @fsa == 'E2J THEN]%%
<table><tr> <td>Offer content</td></tr></table>
%%[ENDIF]%%

Leave a Reply

Your email address will not be published.