0

We have the below AMPScript that works almost perfect. The only issue is when it fails to generate a unsubscribe link, it defaults to preference center URL. We have a custom unsubscribe managed outside of Marketing Cloud so the profile centre URL doesn't work. What do we need to update so that if the unsubscribe fails to generate it outputs our generic preferences page rather than the current dynamic unsub URL Eg: outputs URL https://website.com/preferences

Thanks Andy

%%[
VAR @globalPrefData, @Contact_ID, @emailID, @emailName, @prefCorName, @prefName, @firstName, @Greeting, @unsubscribeKey, @unsubscribeLink, @unsubscribeURL, @rowSet, @channelName
/* Global preferences data extension */
SET @globalPrefData = "SFReportGlobal" 
/* Unsubscribe link without personal unsub key */
SET @unsubscribeLink = "https://website.com/EmailUnsubscribe?id="
SET @channelName = "Events"
SET @Contact_ID = _SubscriberKey
SET @emailID = _emailid
SET @emailName = emailname_
SET @prefCorName = IsNullDefault(Preferred_Correspondence_Name, "")
SET @prefName = IsNullDefault(Preferred_Name, "")
SET @firstName = IsNullDefault([First Name], "")
/* Greeting selection */
IF @prefCorName != "" THEN 
 SET @Greeting = ProperCase(Trim(@prefCorName)) 
ELSEIF @prefName != "" THEN 
 SET @Greeting = ProperCase(Trim(@prefName)) 
ELSE 
 SET @Greeting = ProperCase(Trim(@firstName)) 
ENDIF 
/* Checking test SK */
IF Substring(@Contact_ID,1,3) != "005" THEN
SET @rowSet = LookupRows(@globalPrefData,"18 Digit SF ID",@Contact_ID,"Channel Preference Setting: ChannelPreference",@channelName)

/*New Code Starts here*/
set @count = RowCount(@Rowset)
if (@count > 0) then
/*New Code ends here*/

SET @unsubscribeKey = FIELD(ROW(@rowSet,1), "Unsubscribe Key")
SET @unsubscribeURL = Concat(@unsubscribeLink,@unsubscribeKey)


/*New Code Starts here*/
endif
/*New Code ends here*/

ELSE
SET @unsubscribeURL = profile_center_url
ENDIF
]%%
0

I'm a bit confused, if you don't want the user to ever be directed to the profile center url, then why are you using it as a fallback unsub url in your code for all SubscriberKey's beginning with "005"? Seems like it would just be safer to assign that to the generic preference center (even if you set up your Skey's such that only test users begin with 005) in order to make sure no one is ever sent to the profile center url by accident.

You'd need to update that last unsubscriberURL variable assignment to direct to another URL in order to remedy this. Also, you need assign an else statement for the portion that checks the rowcount returned from the LookupRows function. If there are no rows found, then you'd want to assign the unsubscriberURL value to match the generic preferences page list in your question above.

You may also want to check that final value for unsubscriberURL where rowcount > 0 just to make sure it isn't NULL, so you can redirect to the correct location in the event it found a row but couldn't pull a specific value from it.

  • Hi Jason, Thanks for your reply. The code was written by a 3rd party a while hack so not sure why the profile centre URL as the fall back. It should be setup so that if it fails to generate the dynamic unsub doesnt generate then take them to the website preferences page. Unfortunately my AMPScript ability is very poor so not sure how to amend. I tried changing the last unsubscriberURL but it didnt work which i guess is because of the other part around putting else statement which i dont know how to do. maybe a really silly question but what is the row count, What is it checking ? – Andyw Jun 17 at 4:04

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.