Email Script not populating URL correctly | Community
Skip to main content
Level 2
March 21, 2025
Solved

Email Script not populating URL correctly

  • March 21, 2025
  • 1 reply
  • 1003 views

Hello community,

 

Facing an issue with velocity script, the url variable is not populating correctly & the output is "${url}".

If https:// is included in the baseUrl variable, it works, and the URL is populated correctly, but the click link tracking is lost in the activity log.

What could be the issue here & how can it be fixed without losing the click-link tracking?

 

#set($utm_source="Nurture")
#set($utm_content="WXDWW")
#set($utm_term="20AQR")
#set($utm_id = "utm_id=NewsletterENThink")

#set($baseUrl = "www.abc.com/account/reg/us-en/signup?utm_source=$utm_source&utm_content=$utm_content&utm_term=$utm_term") 

#set($url =$baseUrl+"&" + $utm_id) 

<a style="border-collapse: collapse; mso-line-height-rule: exactly; text-decoration: none; color: hashtag#0f62fe;" href="https://${url}" target="_blank" rel="noopener"> Subscribe now </a>

 

Best answer by SanfordWhiteman

You shouldn’t be building URLs manually in this day and age — you’ll inevitably mess up encoding.

 

Simply use LinkTool ($link) to build the URL, then output the constant https:// followed by the relevant URL parts:

#set( $signupUrl = $link.uri("https://www.example.com/account/reg/us-en/signup") ) #set( $void = $signupUrl.setParam("utm_source", "Nurture", false) ) #set( $void = $signupUrl.setParam("utm_content", "WXDWW", false) ) #set( $void = $signupUrl.setParam("utm_term", "20AQR", false) ) #set( $void = $signupUrl.setParam("utm_id", "NewsletterENThink", false) ) <a style="border-collapse: collapse; mso-line-height-rule: exactly; text-decoration: none; color: #0f62fe;" href="https://${signupUrl.getHost()}${signupUrl.getPath()}?${signupUrl.getQuery()}" target="_blank" rel="noopener"> Subscribe now </a>

 

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
March 22, 2025

You shouldn’t be building URLs manually in this day and age — you’ll inevitably mess up encoding.

 

Simply use LinkTool ($link) to build the URL, then output the constant https:// followed by the relevant URL parts:

#set( $signupUrl = $link.uri("https://www.example.com/account/reg/us-en/signup") ) #set( $void = $signupUrl.setParam("utm_source", "Nurture", false) ) #set( $void = $signupUrl.setParam("utm_content", "WXDWW", false) ) #set( $void = $signupUrl.setParam("utm_term", "20AQR", false) ) #set( $void = $signupUrl.setParam("utm_id", "NewsletterENThink", false) ) <a style="border-collapse: collapse; mso-line-height-rule: exactly; text-decoration: none; color: #0f62fe;" href="https://${signupUrl.getHost()}${signupUrl.getPath()}?${signupUrl.getQuery()}" target="_blank" rel="noopener"> Subscribe now </a>

 

ssRD25Author
Level 2
April 2, 2025

@sanfordwhiteman thank you for the solution but the core issue still exists.

When using the below script, in email preview the link is populating correctly but when email is sent via campaign the output is:

 

https://${signupUrl.getHost()}${signupUrl.getPath()}?${signupUrl.getQuery()}

 

#set( $signupUrl = $link.uri("https://www.example.com/account/reg/us-en/signup") ) #set( $void = $signupUrl.setParam("utm_source", "Nurture", false) ) #set( $void = $signupUrl.setParam("utm_content", "WXDWW", false) ) #set( $void = $signupUrl.setParam("utm_term", "20AQR", false) ) #set( $void = $signupUrl.setParam("utm_id", "NewsletterENThink", false) ) <a style="border-collapse: collapse; mso-line-height-rule: exactly; text-decoration: none; color: #0f62fe;" href="https://${signupUrl.getHost()}${signupUrl.getPath()}?${signupUrl.getQuery()}" target="_blank" rel="noopener"> Subscribe now </a>

 

 

If mktNoTrack class is added to the script the link populates correctly but then the 'Click Email' activity is lost & not captured in the activity log.

<a class="mktNoTrack" style="border-collapse: collapse; mso-line-height-rule: exactly; text-decoration: none; color: #0f62fe;" href="https://${signupUrl.getHost()}${signupUrl.getPath()}?${signupUrl.getQuery()}" target="_blank" rel="noopener"> Subscribe now </a>

 

SanfordWhiteman
Level 10
April 2, 2025

Well, I’ve tested that exact code (wouldn’t have posted it without testing) and it’s working in our lab instance.

 

Can you tell me exactly what kind of campaign you’re using?