0

I have used the below code for unsubscribing the user. It is working fine when I am passing the CloudPageURL() in the footer but when I am passing it in a cloud page it is not working. I want to create a unsubscribe page like when a user clicks on the link it should open a cloud page asking whether the user wants to unsubscribe from a campaign/list or from the organisation i.e Unsubscribing from All Subscriber List.

%%[

var @debug var @jid var @listid var @batchid var @email var @skey var @reason var @unsubscribeAll

set @debug = 0 set @jid = AttributeValue("jobid") set @listid = AttributeValue("listid") set @batchid = AttributeValue("_JobSubscriberBatchID") set @email = AttributeValue("emailaddr") set @skey = AttributeValue("_subscriberkey") set @reason = "One-Click Unsubscribe" set @unsubscribeAll = RequestParameter("ua")

/* if we know the subscriber */ if not empty(@skey) then

var @lue var @lue_prop var @lue_statusCode var @overallStatus var @requestId var @Response var @Status var @Error

/* if unsubscribing from all, then set the job, batch and listids to blank, effectively doing a global unsub */ if @unsubscribeAll == "1" then set @jid = "" set @listid = "" set @batchid = "" endif

/* create a request to inject an unsub event into the LogUnsubEvent platform table */ set @lue = CreateObject("ExecuteRequest") SetObjectProperty(@lue,"Name","LogUnsubEvent")

/* In order to invoke the request, we need to associate the following information with it to define the subscriber context and the job context:

1. Subscriber Key
2. JobId associated with the email send
3. ListID the email was sent to
4. BatchID the email was sent to
5. Reason for the unsub    */ /* 1. define and associate Subscriber Key to the request */ set @lue_prop = CreateObject("APIProperty") SetObjectProperty(@lue_prop, "Name", "SubscriberKey") SetObjectProperty(@lue_prop, "Value", @skey) AddObjectArrayItem(@lue, "Parameters", @lue_prop)

/* 2. define and associate JobID to the request */ if not empty(@jid) then set @lue_prop = CreateObject("APIProperty") SetObjectProperty(@lue_prop, "Name", "JobID") SetObjectProperty(@lue_prop, "Value", @jid) AddObjectArrayItem(@lue, "Parameters", @lue_prop) endif

/* 3. define and associate ListID to the request */ if not empty(@listid) then set @lue_prop = CreateObject("APIProperty") SetObjectProperty(@lue_prop, "Name", "ListID") SetObjectProperty(@lue_prop, "Value", @listid) AddObjectArrayItem(@lue, "Parameters", @lue_prop) endif

/* 4. define and associate BatchID to the request */ if not empty(@batchid) then set @lue_prop = CreateObject("APIProperty") SetObjectProperty(@lue_prop, "Name", "BatchID") SetObjectProperty(@lue_prop, "Value", @batchid) AddObjectArrayItem(@lue, "Parameters", @lue_prop) endif

/* 5. define and associate unsub reason to the request */ set @lue_prop = CreateObject("APIProperty") SetObjectProperty(@lue_prop, "Name", "Reason") SetObjectProperty(@lue_prop, "Value", @reason) AddObjectArrayItem(@lue, "Parameters", @lue_prop)

/* finally, you invoke the request */ set @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)

/* extract messages from the response */ set @Response = Row(@lue_statusCode, 1) set @Status = Field(@Response,"StatusMessage") set @Error = Field(@Response,"ErrorCode")

endif

if @debug == 1 then output(concat(" jid: ", @jid)) output(concat(" listid: ", @listid)) output(concat(" batchid: ", @batchid)) output(concat(" email: ", @email)) output(concat(" skey: ", @skey)) output(concat(" reason: ", @reason)) output(concat(" unsubscribeAll: ", @unsubscribeAll)) output(concat(" overallStatus: ", @overallStatus)) output(concat(" requestId: ", @requestId)) output(concat(" Response: ", @Response)) output(concat(" Status: ", @Status)) output(concat(" Error: ", @Error)) endif

]%%

And this is the code I used in my Cloud Page

Thank You!

  1. Click Here if you want to opt-out of this campaign. You may recieve communication from ABC regarding other information or campaign.

  2. Click Here if you want to never recieve any mails from ABC.

4

First of all, you need to pass all the variables to the CloudPage that has the unsubscribe script.

The best way is to include name and value pairs for each of your variables as parameters in the URL. Here is the documentation.

And this is an example of how your URL could look like:

 %%=CloudPagesURL(ID, 'JobID', @jid, 'ListID', @listid, 'BatchId', @batchid, 'Email', @email, 'SubKey', @skey)=%%

On the unsubscribe CloudPage, instead of using the AtributeValue function, you would have to use the RequestParameter function:

SET JobID = RequestParameter('JobID')

and so on for the remaining parameters.

Now for the two options you have:

  1. If the subscriber wants to unsubscribe just from one campaign/list, you need to make sure that the correct @listid is passed to the script. Note that it will only work if you're using lists/publication lists - if you're using data extensions to store consent information, you need to take a different approach here. This might help.
  2. If the subscriber wants to unsubscribe from all emails, you need to set the job, batch and listids to blank, effectively doing a global unsubscribe
  • Thank You! It is working perfectly :) – Shrijeet Khonde Sep 24 at 13:15

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.