You can use the LogUnsubEvent code found here to unsubscribe the person from the Business Unit and also log the event in the tracking associated with the email send job.
In order to use this correctly, you need to use the MicrositeURL(if using a Landing Page) or CloudPagesURL (if using a CloudPage) function in your email unsubscribe link. This ensures that the subscriber attributes are accessible within the Landing Page/Cloud Page
%%[
SET @sid = emailaddr
SET @jid = jobid
SET @listid = listid
SET @batchid = batchid
SET @reason = "Profile Center Unsubscribe"
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")
]%%
Use the following code to determine which Lists (also Publication Lists) a subscriber is a part of.
Make sure your email is using %%=MicrositeURL(xxxxx)=%%
or %%=RedirectTo(CloudPagesURL(xxxxx))=%%
.
This ensures that the Landing Page/CloudPage has access to the subscriber's attributes (such as Subscriber Key)
%%[
SET @subscriberKey = _subscriberkey /*Retrieve the Subscriber Key into a variable*/
]%%
<script runat="server">
Platform.Load("core", "1.1.1")
var subKey = Variable.GetValue("@subscriberKey") //Assign to SSJS variable
var subObj = Subscriber.Init(subkey) //Initiate Subscriber Object
var listJSON = subObj.Lists.Retrieve() //Retrieve lists that the subscribers is a part of
for (var i = 0; i < listJSON.length; i++){ //Loop through all the lists and print them out in HTML
var listName = listJSON[i]["List"]["Name"]
var listStatus = listJSON[i]["Status"]
</script>
<body>
List Name:<ctrl:var name=listName /> <br />
List Status:<ctrl:var name=listStatus /> <br />
</body>
<script runat="server">
Platform.Load("core", "1.1.1")
} //End of loop
Write("Debug - Subscriber JSON:" + Stringify(listJSON)) //Used for debugging to find the object names
</script>
Best Answer
If you are properly updating list membership using the SubscriberList object (as demonstrated in the code sample referenced in your comment), then the list is basically the same Publication List.
You can select Lists in UI Send Definitions.