FKD Services

How to Setup AMPScript Unsubscribe in Salesforce Marketing Cloud

Unsubscribe from Email

You can build an customised page for your marketing activity using AMPScript Unsubscribe and this post will show you how.

Marketing Cloud Solutions

Salesforce Marketing Cloud offers you two options to unsubscribe customers. The first is a one click unsubscribe. The other is a preference centre where customers can manage which communications they want to receive.

The issue I found with these options was, it’s all all out of the box solution that doesn’t allow for much customer journey customisation or branding.

Solution using AMPScript

AMPScript is a programmatic language that allows you to extend the functionality of your Marketing Cloud platform. It allows you to build logic into emails, landing pages and many more.

I created a Cloud Page that would confirm to customers that they had successfully unsubscribed from marketing activity. We also had to make sure unsubscribe event was running in the background to ensure SFMC registered the customers clicks.

Using AMPScript Unsubscribe seems to be the most effective way to achieve this and after a bit of looking online, across this video which of super useful.

OneClick AMPScript Unsubscribe

This youtube video will walk you through the end to ends process on how to build your own AMPScript page with one-click unsubscribe.

After implementing the solution, I had some technical issues which I have documented in the troubleshooting section of this post.

The AMPScript Code

//AMPScript Unsubscribe for emails in Marketing Cloud

%%[
VAR @sid, @jid, @reason, @lue, @lue_prop, @lue_statusCode,
@overallStatus, @requestId, @Response, @Status, @Error

SET @sid = AttributeValue(“_subscriberkey“) //unique contact id
SET @jid = AttributeValue(“jobid“) //unique reference from the email
SET @listid = AttributeValue(“listid“) // unique id for the publication list.
SET @batchid = AttributeValue(“_jobSubscriberbatchid“)
SET @reason = “One Click Email Unsubscribe// Source for unsubscribe

/* Conditional logic to ensure that, on page load, values for subscriber key,
publication id and email id are present*/

IF NOT EMPTY(@sid)
AND NOT EMPTY(@jid)
AND NOT EMPTY(@listid)
THEN

SET @lue = CreateObject(“ExecuteRequest“)
SetObjectProperty(@lue,”Name“,”LogUnsubEvent“)

SET @lue_prop = CreateObject(“APIProperty“)
SetObjectProperty(@lue_prop, Name“, “SubscriberKey“)
SetObjectProperty(@lue_prop, “Value“, @sid)
AddObjectArrayItem(@lue, “Parameters“, @lue_prop)

SET @lue_prop = CreateObject(“APIProperty“)
SetObjectProperty(@lue_prop, “Name“, “JobID“)
SetObjectProperty(@lue_prop, “Value“, @jid)
AddObjectArrayItem(@lue, “Parameters“, @lue_prop)

SET @lue_prop = CreateObject(“APIProperty“)
SetObjectProperty(@lue_prop, “Name“, “ListID“)
SetObjectProperty(@lue_prop, “Value“, @listid)
AddObjectArrayItem(@lue, “Parameters“, @lue_prop)

SET @lue_prop = CreateObject(“APIProperty“)
SetObjectProperty(@lue_prop, “Name“, “BatchID“)
SetObjectProperty(@lue_prop, “Value“, @batchid)
AddObjectArrayItem(@lue, “Parameters“, @lue_prop)

SET @lue_prop = CreateObject(“APIProperty“)
SetObjectProperty(@lue_prop, “Name“, “Reason“)
SetObjectProperty(@lue_prop, “Value“, @reason)
AddObjectArrayItem(@lue, “Parameters“, @lue_prop)

SET @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)

SET @Response = Row(@lue_statusCode, 1)
SET @Status = Field(@Response,”StatusMessage“)
SET @Error = Field(@Response,”ErrorCode“)

// shows status after a successful unsubscribe
outputline(concat(“Status: “,@Status))
ELSE
//default copy of the unsubscribe load is loaded without the subscriberkey/listid/emailid
outputline(concat(“Click on the link in the email to unsubscribe“, “”))

ENDIF
]%%

Troubleshooting AMPscript Unsubscribe

Troubleshooting AMPScript Unsubscribe

One of the issues I had after implementing the AMPScript on my page was, I was getting a 500 server error. Marketing Cloud is quite poor when it comes to providing any feedback as to what was wrong.

After a bit of troubleshooting, it looked like the URL after a customer had clicked the link had two question marks (“?”), one for the landing page itself and another for the UTM tracking parameters we had on our platform.

The fix was to use a sub string instead of the actual landing page URL

%%=CONCAT(CloudPagesURL(XXX), SUBSTRING(‘?’, 1, 0))=%%

Useful Links

How a Subscriber Opts Out

List Unsubscribe

Subscribers Status in Marketing Cloud

YouTube Video for OneClick Unsubscribe

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *