Need some easy options for geotargeting in Salesforce Marketing Cloud Engagement (ex-ExactTarget)? I have 3 super easy options for you to target by state or postal code.
By state
By postal code radius
By a very large postal code radius, or multiple
And for each, I’ll give examples on how to:
Segment your audience to control who receives an email
Personalize your email to control who sees content in an email
1) List Of States
Okay, that sounds too easy, right? Anyone can list a bunch of rules in a filtered data extension or in Journey Builder.
That works great. But here is our first tip, accomplishing it in a single line using the “exists in whole word” operator:
This operator is great for checking if the entire value of your field (e.g. “MN”) is found on that list of values.
Alright, let’s look at some AMPscript if you only want to show/hide content within an email going to a larger audience. Similar to a drag and drop filter, most devs start with the obvious:
%%[
if @state == "MN" or @state == "WI" or @state == "IA" or @state == "ND" or @state == "SD" then
set @show_midwest_content = true
endif
]%%
And again similarly, we can accomplish this with a list of values, using AMPscript’s IndexOf()
operator. This allows us to check if a smaller string is contained within a larger string, which conveniently works to check if a field’s value is contained within a list of values. (Learn more here.)
%%[
/* A bit more literal */
set @midwest_states = "MN,WI,IA,ND,SD"
if IndexOf(@midwest_states,@state) != 0 then
set @show_midwest_content = true
endif
/* A bit shorter */
if IndexOf("MN,WI,IA,ND,SD",@state) != 0 then
set @show_midwest_content = true
endif
]%%
Either of these options is a bit shorter than listing out each state with an or
operator.
2) Postal Code Radius
Spoiler: This is the same solution as states, but we’re going to take a quick detour to one of my favorite bookmarks, US or Canada postal code radius generator by freemaptools.com.
To get started, select your radius in kilometers or miles, enter your starting postal code, and click Search.
Scroll down to ZIP Codes where you can see how many other postal codes are contained within that radius. They should be in a list separated by commas — click Copy To Clipboard.
Now head back to your filter in SFMCE and use the “exists in whole word” operator again.
Quirky display aside, yes, this actually does work.
At least, within limits. I’ve done it without issues up to a couple hundred values, but I wouldn’t recommend over 500. (Salesforce support probably wouldn’t recommend it at all.) So if you need a really large list, scroll on to #3 below.
But first, a quick example of how the same IndexOf()
solution works here for using AMPscript to show/hide content based on the postal code radius:
%%[
set @postal_code_radius = "55442,55428,55446,55441,55427,55447,55429,55422,55569,55369,55445,55311,55430,55443,55305,55412,55426,55411,55340,55444,55391,55405,55416,55403,55356,55316,55432,55401,55421,55402,55479,55418,55345,55470,55343,55440,55458,55459,55480,55483,55484,55485,55486,55433,55487,55474,55488,55408,55323,55413,55415,55599,55436,55467,55404,55454,55361,55455,55424,55409,55410,55327,55414,55374,55592,55577,55593,55357,55407,55448,55419,55346,55112,55434,55439,55384,55406,55344,55435,55114,55359,55108,55113,55417,55423,55341,55364,55331,55449,55104,55126,55373,55317,55347,55105,55376,55450,55438,55103,55116,55572,55437,55111,55303,55304,55431,55117,55420,55127,55150,55014,55386,55155,55102,55425,55146,55130,55131,55133,55145,55164,55170,55120,55101,55301,55107,55118,55328,55375,55318,55121,55106,55109,55337,55378,55122,55330,55110,55379,55388,55387,55119,55123,55075,55144,55313,55011,55306,55090,55077,55128,55363,55038,55124,55115,55055,55076,55025,55125,55070,55372,55092,55360,55005,55322,55042,55362,55315,55071,55390,55068,55367,55129,55398,55082,55352,55309,55044,55016,55397,55040,55083,55047,55358,55349,55001,55079,55368,55003,55020,55395,55308,55078,55024,55073,55054,54082,55043,55339,55354,56011,55085,55013,55033,55370,56071,54016,55088,55008,55321,54025,55010,55302,55381,55338,55045,55371,55031,55320,55377,55319,55056,55065,55382,55046,55074,54021,55057,56044,55029,55012,54020,55336,54022,54023,55017,55032,55080,56069,55325,56304,55019,55084,55307,54017,54026,54009,56363,55353,55089,55009,55366,54015,56058,55324,55018,56057,56357,55006,56330,55069,54024,55334,56397,56398,54014"
if IndexOf(@postal_code_radius,@postal_code) != 0 then
set @show_event_content = true
endif
]%%
3) Bigger Postal Code Radius
You need a really large postal code radius, or multiple radiuses? (Radii? Weird. Let’s stick with radiuses.) Or maybe you just don’t want to abuse/crash SFMCE with that big of a list of values.
No problem, we have another great option.
Starting back at freemaptools.com, search for your larger list of postal codes — but this time, click the Toggle CSV or New Line button so your results are on individual lines before clicking Copy To Clipboard.
Paste that list into Notepad or a code editor following “postal_code” and save as a .txt file.
postal_code
55442
55428
55446
55441
...
If you’re working with multiple postal code radiuses, you can combine them by pasting multiple lists here into the same file.
What we’re going to do is create a new data extension in SFMCE containing all of your postal codes, then create a data relationship between your main data extension (wherever your starting point is for an email audience) and the postal codes.
Create a new Standard Data Extension — on the (3) Fields tab, add two fields:
postal_code (or whatever your postal code field is typically named), set as the Primary Key
in_radius — a Boolean field that is Nullable and has a Default Value of True
Once you’ve created it, import your .txt file, and it should automatically populate that in_radius field for you.
Next, create a Data Relationship between your starting data extension and the one you just created, joining on postal_code. As long as your new data extension has postal_code as the primary key (unique identifier) and your starting data extension also has postal_code, you should see the all-important data filter checkbox checked, indicating that you can use this in a filter.
Head back to your filtered data extension, scroll down past the field names to Data Relationships, and open the new one you just created. Drag over the in_radius field and set to is true.
(I apologize for the gray boxes here, redacting some fields and other data relationships not relevant to this use case and not wanting to overshare my company’s data model.)
If you’re not familiar with data relationships, we just created a forced join between the two tables, so they will only be included in your filtered results if their postal_code is in your new list of postal_code values. (For SQL users, this is equivalent to an INNER JOIN
on the postal_code field.)
Now you’re all set, with an audience filtered to only subscribers in a very large postal code radius (or one of multiple).
For showing/hiding content in an email, AMPscript can easily target this same data extension with Lookup()
to check.
%%[
set @postal_code = AttributeValue("postal_code")
/* Connect to the "postal_code_radius" DE to get "in_radius", matching on "postal_code". */
set @in_radius = Lookup("postal_code_radius","in_radius","postal_code",@postal_code)
if @in_radius == true then
set @show_event_content = true
endif
And there you have it — three easy copy-and-paste-friendly methods for geotargeting in SFMCE. Share any easy tips I missed in the comments, and thanks for reading!
Top comments (0)