LogUnsubEvent with AMPscript Not Logging All Items

ampscriptcloudpagemarketing-cloudtrackingunsubscribe

Using the AMPscript below, these items are not being logged:

  • JobID

  • ListID

  • BatchID

  • Reason

The AMPscript exists on a CloudPage.

Tracking > EmailName > Overview tab > Inbox Activity > Unsubscribes

Only Subscriber Key, Email, and Unsubscribe Time are logged

Subscriber properties > History tab

Only Date, Activity, Email are logged

Is there a way to get all of the items logged?

%%[

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

SET @sid = TRIM(_subscriberkey)
SET @jid = TRIM(jobid)
SET @listid = TRIM(listid)
SET @batchid = TRIM(_JobSubscriberBatchID)
SET @reason = "One-click unsub"

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")

]%%

Best Answer

Your AMPscript code looks correct except the beginning where I am not sure why you are trimming JobID, ListID, and BatchID system strings when they are always going to be a numeric identifier without the leading and trailing spaces by default.

Answering your question, it seems that you have not quite fully understood how UnsubEvent logging works. What you mention is the correct places and info you can find there and you cannot extend it with JobID, ListID, and BatchID values. In other words, if you found your SubscriberKey, Email, and UnsubscribeTime at Tracking > EmailName > Overview tab > Inbox Activity > Unsubscribes then it already means that it was logged correctly, even though you do not see columns and values for JobID, ListID, and BatchID. On contrary, if you have not supplied JobID or ListID to the UnsubEvent logging, then you would unsubscribe a subscriber but it will not be tracked anywhere. You can easily test this by commenting out this part from your code and sending a test email to get unsubed -

/* SET @jid = TRIM(jobid)
SET @listid = TRIM(listid)
SET @batchid = TRIM(_JobSubscriberBatchID) */

That is why I would recommend to review this article by Zuzanna Jarczynska that explain in all detail how UnsubEvent logging works and on top of that, there is also publicly available Adam Spriggs gist on GitHub with good comments on UnsubEvent logging via AMPscript

Related Topic