A case for the MicrositeURL() function

Do you know about the MicrositeURL() AMPScript function? It’s relatively new. It sure is handy if you’re building custom preference centers in Enterprise 2.0 business units.

The idea is that you can encrypt custom parameters in your email links to Microsite pages and then retrieve the unencrypted values with an AMPScript function. Once you have the business unit MID in the microsite page, you can use it to ensure your API calls are for the correct business unit.

In your email you would have this code:

<a href='%%=MicrositeURL(888888,"subscriberMID", "12345678")=%%'>Update Profile</a>

The 888888 is the Page ID of the Microsite page, and 12345678 is the business unit MID for the originating email send.

In your Microsite page, you’d have the following AMPScript block:

var @subscriberMID
set @subscriberMID = iif(empty(RequestParameter("subscriberMID")),memberid, RequestParameter("subscriberMID"))

In the case where the the subscriberMID is not set, default to the parent business unit’s MID, which is accessible from the memberid personalization string.

One gotcha: If you build your custom preference centers with Server-Side Javascript, there’s no SSJS function to retrieve the additional MicrositeURL parameters — you to use AMPScript. Your code may end up looking something like this:

<script type="text/javascript" runat="server">
    Platform.Load("core", "1.1.1");
    </script>%%[set @subscriberMID = RequestParameter("subscriberMID")]%%<script type="text/javascript" runat="server">

    if (Variable.GetValue("@subscriberMID") != "") {
        memberid = Variable.GetValue("@subscriberMID");
    } else {
        memberid = Attribute.GetValue("memberid");

For further reading:
Personalization Strings
Server-Side JavaScript

Regular Expressions in AMPScript

Did you know you can use regular expressions in AMPScript?

You can.

Here are some RegExMatch() snippets that I’ve used:


@s = input string
@p = pattern
@m = match
@o = output

Sample Code

var @s, @o, @p, @m

outputLine(concat("<h4>Strip leading zeroes from a string</h4>"))
set @s = "0000012345"
set @p = "^0*(\d+)$"
set @o = RegExMatch(@s, @p, 1)
outputLine(concat("input:  ",@s,"<br>"))
outputLine(concat('pattern: "',@p,'"<br>'))
outputLine(concat("output: ",@o,"<br>"))

outputLine(concat("<h4>Check for all digits, no match</h4>"))
set @s = "12345x"
set @p = "^\d*$"
set @o = RegExMatch(@s, @p , 0)
outputLine(concat("input: ",@s,"<br>"))
outputLine(concat('pattern: "',@p,'"<br>'))
outputLine(concat("output: ",@o,"<br>"))

outputLine(concat("<h4>Check for all digits, match</h4>"))
set @s = "12345"
set @p = "^\d*$"
set @o = RegExMatch(@s, @p , 0)
outputLine(concat("input: ",@s,"<br>"))
outputLine(concat('pattern: "',@p,'"<br>'))
outputLine(concat("output: ",@o,"<br>"))

outputLine(concat("<h4>Replace parenthetical text with space</h4>"))
set @s = "whee (whatever it is) whoop"
set @p = "\s\(.+\)\s"
set @m = RegExMatch(@s, @p, 0 , "IgnoreCase")
set @o = replace(@s,@m, " ")
outputLine(concat("input:  ",@s,"<br>"))
outputLine(concat('pattern: "',@p,'"<br>'))
outputLine(concat("match: ",@m,"<br>"))
outputLine(concat("replaced: ",@o,"<br>"))



Strip leading zeroes from a string

input: 0000012345
pattern: “^0*(\d+)$”
output: 12345

Check for all digits, no match

input: 12345x
pattern: “^\d*$”

Check for all digits, match

input: 12345
pattern: “^\d*$”
output: 12345

Replace parenthetical text with space

input: whee (whatever it is) whoop
match: (whatever it is)
pattern: “\s\(.+\)\s”
output: whee whoop

For further reading

RegExMatch() function
Concat() function
OutputLine() function
RegEx pattern reference
RegEx options reference