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.


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>
| improve this answer | |
  • 1
    Too quick for me @LukasLunow. I was literally just typing up the same things. One note is I would declare the personalization strings (especially if they are coming from a DE, not the default ones) via the AttributeValue() function for better null handling. – Gortonington May 7 '19 at 15:04
  • 1
    That was a cheap one for me, @Gortonington. Thanks for the upvote -> good sportsmanship there. Added AttributeValue() - thanks for the heads-up – Lukas Lunow May 7 '19 at 15:05
  • 1
    Here's another one from me for being quick on the draw @LukasLunow – Jason Hanshaw May 7 '19 at 15:06
  • Please don't forget to mark the answer as accepted, if this has been helpful – Lukas Lunow May 8 '19 at 11:52

You need to concatenate your parameters onto the URL and then call the entire URL in RedirectTo. So something like this:

    SET @apt_alt_1_image = Pre_Platform_Inquiry__c:First_Apartment_Alternative__r:Link__c
    SET @concat_url = CONCAT(@apt_alt_1_image,"?om_cmpgn=",emailname_,"&utm_cmpgn=",@utm_cmpgn,"&om_medium=email&utm_term=apt_alt_1_image")

    <a href="%%=RedirectTo(@concat_url)=%%">Link</a>
| improve this answer | |
  • thank you! For values like %%emailname_%% which are system variables, would I need to define the variable like SET @ emailname = %%emailname_%% or can it be placed in the concat_url as "?om_cmpgn="%%emailname%%"? – Greg Beazley May 7 '19 at 15:35
  • 1
    I always set all values that will be used within the email send just to be sure, but you do not have to set those standard personalization strings before you call them in your ampscript block. Also, in the concat function, do not use those percents like that. Just call it as "emailname_" in it's own comma separated argument and leave off those symbols. – Jason Hanshaw May 7 '19 at 15:51
  • 1
    @JasonHanshaw - please do observe, you are referencing utm_cmpgn as if it was a valid personalisation string, which it isn't – Lukas Lunow May 7 '19 at 15:53
  • 1
    Yep, you're right, this is not a personalization string. I've updated to make that a bit more obvious. Thanks! – Jason Hanshaw May 7 '19 at 17:03

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.