Marketo Velocity Script Error While Changing CTA Link Based on Lead Country | Community
Skip to main content
New Member
July 7, 2026
Question

Marketo Velocity Script Error While Changing CTA Link Based on Lead Country

  • July 7, 2026
  • 1 reply
  • 8 views

Hi everyone,

I have a requirement where the email content remains the same, but the CTA link needs to change dynamically based on the lead's country using a Velocity Script in Marketo.

However, I'm getting an error when I deploy the campaign.

Requirement:

Behavior:

  • ✅ Email Preview: Works as expected.
  •  

  • ❌ Smart Campaign Send: Fails with a Velocity Script error.

Velocity Script:

#set($country = ${lead.Country})
#set($url = "www.google.com")
#if($country == "India")
    #set($url = "example.com/in")
#elseif($country == "United States")
    #set($url = "www.youtube.com ")
#elseif($country == "Canada")
    #set($url = "example.com/ca")
#else
    #set($url = "www.google.com")
#end

${url}

HTML:

 <td valign="top" align="center" style="text-align: center; padding: 12px 20px; color: #1570EF; font-size: 16px; font-family:Arial; font-weight: bold;background-color: #FFFFFF;" bgcolor="#FFFFFF;"> <span class="mktoText" id="text" mktoname="text" style="color:#1570EF; background-color:#FFFFFF;  text-decoration: none !important;"><p><a href="https://{{my.urlcountry}}" target="_blank" style="text-decoration: none !important; color: #1570ef;" data-bipfieldlink="Text-12" data-=""><strong style="text-decoration: none;" data-bipfieldid="Text-12" data-bipfieldlabel="Banner CTA">${CtaText}</strong></a></p></span> </td> 

Error:

 

 

Has anyone encountered this issue before? Am I missing something in the Velocity syntax, or is there a better approach for dynamically changing CTA links based on the lead's country?

Any help or suggestions would be greatly appreciated. Thank you!

1 reply

BlaneMcMichen-1
Adobe Employee
Adobe Employee
July 7, 2026

Hi

This has been explained in this post, but you cannot use a local script token to complete a url within a tracked link.

Use this setup:

Email Script Token

#set($country = $lead.Country)
#set($url = "https://www.google.com")

#if($country == "India")
#set($url = "https://example.com/in")
#elseif($country == "United States")
#set($url = "https://www.youtube.com")
#elseif($country == "Canada")
#set($url = "https://example.com/ca")
#end

${url}

HTML

 

<a href="{{my.urlcountry}}" target="_blank" style="text-decoration:none !important; color:#1570ef;">
<strong style="text-decoration:none;">${CtaText}</strong>
</a>

If it still doesn't work

The likely reason is Marketo tracked-link compilation with Email Script Tokens. In that case:

<a href="{{my.urlcountry}}" class="mktNoTrack" target="_blank" style="text-decoration:none !important; color:#1570ef;">
<strong style="text-decoration:none;">${CtaText}</strong>
</a>

Why this fixes it

Issue Fix
Invalid variable assignment syntax Use $lead.Country instead of ${lead.Country} inside #set
Bad URL output Remove trailing spaces and include full https:// URLs
Token mismatch Make sure {{my.urlcountry}} is the actual Email Script Token name
Link tracking/resolution issues Use fully formed URLs or class="mktNoTrack" if needed