3

In Salesforce Marketing Cloud (SFMC), I want to unsubscribe a contact from a single publication list by using a form on a landing page.

I also want to create an Unsub event in SFMC when they submit the form.

There is some sample code from SFMC Help documents here that seems to do that for external sites. Will it work in a SFMC hosted landing page? Do I need to edit the code much?

7

The code in the documentation should work fine, you just need to make sure the required variables all get set properly before executing the API calls.

This piece of code is using the RequestParameter function to set @sid, @jid, @listid and @batchid from a form. You would want to create a form that POSTs to a page that contains this AMPscript.

SET @sid = IIF(Empty(RequestParameter("email_address")),RequestParameter("current_email_address"),RequestParameter("email_address"))
SET @jid = RequestParameter("jobid")
SET @listid = RequestParameter("listid")
SET @batchid = RequestParameter("batchid")

One thing about the code sample on their docs is that it sets a variable called @sid, which is used to actually set the SubscriberKey, this is sort of misleading because not all accounts use the email address as Subscriber Key.

How I do this

Just to make things easier for you I will post the full code that I use on my Preference Center.

You are going to need a way to pass the required values from the email to the landing page. One good way to send the values behind the scenes to the microsite is to use the Microsite_URL function when linking to your preference center.

In your email:

<a href="%%=MicrositeURL(123456)=%%">Unsubscribe</a>

Note: replace 123456 with the Id if your landing page

On the landing page:

    VAR @sid, @jid, @listid, @batchid, @reason, @lue, @lue_prop, @lue_statusCode, @overallStatus, @requestId, @lue_Response, @lue_Status, @lue_Error
    SET @sid = SubscriberID
    SET @jid = JobID
    SET @listid = ListID
    SET @batchid = _JobSubscriberBatchID
    SET @reason = "Landing Page Unsubscribe"

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

    SET @lue_prop = CreateObject("APIProperty")                 
    SetObjectProperty(@lue_prop, "Name", "SubscriberID")
    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 @lue_Response = Row(@lue_statusCode, 1)
    SET @lue_Status = Field(@lue_Response,"StatusMessage")
    SET @lue_Error = Field(@lue_Response,"ErrorCode")

The URL that is generated by Microsite_URL does not expose any information in the URL, but allows you to access all the subscriber information on the landing page. One you have the values you can use them however you want, usually in a form or logging the unsub event automatically.

The above code sample will create a one click unsubscribe. Most companies prefer to let their user confirm once they are on the landing page. For this you will need to create a form that POSTs these values or some other page in between the email click and the final unsub processing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.