One-Click Unsubscribe in Marketing Cloud

Feb 27, 2023 | Marketing Cloud

f-how-to-create-a-one-click-unsubscribe-in-marketing-cloud-kwamehq

To support my work, this post may contain affiliate links (these are referrer links sharing products and services. I get paid a small commission if you make a purchase through the link)

How to create a one-click unsubscribe on Marketing Cloud

As a marketer, you need to provide an option for customers to unsubscribe from email communications.

You can build a preference centre allowing customers to choose which types of communication they want from your business.

Alternatively, you can choose to offer them a one-click unsubscribe at the bottom of the email.

This will stop customers from getting marketing communications.

In this post, you’ll explore the unsubscribe solution within Marketing Cloud using AMPScript and SSJS.

This solution will register an unsubscribe event within Marketing Cloud for the subscriber.

This will stop general marketing communication, but there is an option within SFMC to override this for service comms.

You can do this using the transactional sender classification within your email setup.

One-Click Unsubscribe in Marketing Cloud

In order to create a one-click unsubscribe for your customer, you need to know how to create a Cloud page.

You also need to have a good knowledge of AMPScript and SJSS.
The AMPScript will be used to create some logic within the cloud page, and SJSS will be used to create objects within Marketing Cloud servers.

This youtube video will walk you through the end to ends process of building your unsubscribe page with a one-click unsubscribe.

The AMPScript Code

%%[
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

One of the issues I had after implementing the solution above was that I was getting a 500 server error.

Marketing Cloud is relatively 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 and another for the UTM tracking parameters

The fix was to use a concat function and a substring instead of the actual landing page for the unsubscribe page.

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

Conclusion

Marketing Cloud has some useful information that explains in detail the subscriber status and subscriber opt-outs.

If you are using different Lists within Marketing Cloud to manage your email communications, you might want to check out this resource on List Unsubscribe.

0 Comments

Submit a Comment

Pin It on Pinterest