[SalesForce] AMPscript RedirectTo Links breaking + directing to https://click.email

There are a few similar articles about this topic but I haven't found the exact answer I'm looking for.

I have a dynamic link in an email that needs to be tracked.

When I preview and run a test send without tracking, the links render correctly with '?utms' etc. When tracking is applied they break and direct to https://click.email.thehomelike.com/utm_source

Here's an example of the AMPscript I'm using:

%%[SET @apt_alt_1_image = Pre_Platform_Inquiry__c:First_Apartment_Alternative__r:Link__c]%%

<a href="%%=RedirectTo(@apt_alt_1_image)=%%?om_cmpgn=%%emailname_%%&utm_cmpgn=%%utm_cmpgn%%&om_medium=email&utm_term=apt_alt_1_image"

I should note that "Pre_Platform_Inquiry__c:First_Apartment_Alternative__r:Link__c" is a value in the Data Extension that is a complete link already, like "https://app.thehomelike.com/apartment/d49a3c45c2f0fc15ef0f"

There's a paragraph on https://ampscript.guide/redirectto/ that states:
"If the RedirectTo function is not used in the href attribute when an attribute or variable is used, the hyperlink will not be resolved with the attribute or variable, for example it will appear as, https://click.email.com/%%=v(@url)=%%." I don't fully understand what this means and if it's related.

Any assistance is appreciated.

Best Answer

Firstly, I would use Concat function if I were you. Just adding a number of AmpScript blocks within a single string doesn't work. Secondly, there is no such substitution string as utm_cmpgn - so in my review, I included this as a string. What is your intent to use instead of that? You can find the emailname_ and other personalisation strings here. These do not need to be initialised, but can be called directly. Observe these don't need to be prepended with @ - this applies only for variables.

As Gortonington rightfully states in his comments, you should use AttributeValue function when referencing data extension fields - for improve error handling.

Please see the updated code below:

%%[
SET @apt_alt_1_image = AttributeValue("Pre_Platform_Inquiry__c:First_Apartment_Alternative__r:Link__c")
SET @link = Concat(@apt_alt_1_image,'?om_cmpgn=',emailname_,'&utm_cmpgn=utm_cmpgn&om_medium=email&utm_term=apt_alt_1_image')]%%

<a href="%%=RedirectTo(@link)=%%">Link</a>
Related Topic