Last active
February 20, 2020 15:01
-
-
Save wvpv/d4931e7cceebad783ee38d3a2a74dd6e to your computer and use it in GitHub Desktop.
Dynamic brand email with impression region
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%[ | |
/* init block - read the send context and prep you dynamic content here */ | |
/* set this to 0 to disable the debugging output below */ | |
var @debug | |
set @debug = 1 | |
/* get the brand code from the sending data extension (aka the send context) */ | |
var @brandCode | |
set @brandCode = AttributeValue("brandCode") /* this will be the name of your data extension column */ | |
/* skips the email send if no brand exists in the context */ | |
if empty(@brandCode) then | |
raiseError("Missing brandCode", 1) | |
endif | |
/* retrieve the brand info from the BrandContent data extension */ | |
/* adapted from example on https://ampscript.guide/lookuprows */ | |
var @rows, @row, @rowCount, @brandCode, @i | |
set @rows = LookupRows("BrandContent","brandCode", @brandCode) | |
set @rowCount = rowcount(@rows) | |
/* if a brandcontent row is found */ | |
if @rowCount > 0 then | |
/* get the first row in the result set and set variables for specific data extension columns */ | |
set @row = row(@rows, 1) | |
/* add other variables for DE columns as needed */ | |
var @brandHeaderImageURL, @brandName | |
set @brandName = field(@row,"brandName") | |
set @brandHeaderImageURL = field(@row,"brandHeaderImageURL") | |
else | |
raiseError(concat("No BrandContent found for ", @brandCode),1) | |
endif | |
]%% | |
<!-- this debugging output allows you to validate the send context and logic in your init block--> | |
%%[ if @debug == 1 then ]%% | |
<br>brandCode: %%=v(@brandCode)=%% | |
<br>brandName: %%=v(@brandName)=%% | |
<br>brandHeaderImageURL: %%=v(@brandHeaderImageURL)=%% | |
%%[ endif ]%% | |
<!-- this enables impression region tracking for your brandCode, giving you the open and click counts in the Impression Region tracking report --> | |
<!-- adapted from https://ampscript.guide/beginimpressionregion/ --> | |
<!-- impression region reporting has to be enabled in your account, per: https://salesforce.stackexchange.com/q/221773/5202 --> | |
%%=TreatAsContent(concat("%", "%=BeginImpressionRegion('", @brandCode, "')=%", "%"))=%% | |
<!-- your email HTML goes here --> | |
<!-- here's how to set the width on the image from the BrandContent data extension. No need to set the height --> | |
<img src="%%=v(@brandHeaderImageURL)=%%" alt="%%=v(@brandName)=%%" style="width:700px;"> | |
%%=EndImpressionRegion(0)=%% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment