SOLVED

Velocity Token Issue

Go to solution
SaurabhGoyal_GN
Level 4

Velocity Token Issue

 

Hi Everyone!
I am running into an issue and thought of posting the same here - 

We wanted to have survey link tokenized for every language. So we decided to have velocity token in place. 
Survey link structure - Common URL + Query Parameters + Language Code. 
VTL code is pasted below. 
ISSUE - When I am testing the URL in preview mode as a person then its working fine as expected. URL is getting populated. BUT when sending sample email or live email and clicks on link, the link which opens is this - 

$final_url/?mkt_tok=MjYxLU5SWi0zNzEAAAGSqk7_a

 

Else everything like CTA text, styling is working fine. Just link is causing the issue. 

 

 

#set($survey_link = "https://samplelink.com")
#set($utms = "?Q_id={{member.Program_Level_field}}&Q_Language=")


#set($preferred_lang = $lead.Preferredlanguage)

#if($preferred_lang.equals("en-gb")) #set($lang_code = "EN-GB") #set($CTA_text = "Go to survey")
#elseif($preferred_lang.equals("ar")) #set($lang_code = "AR") #set($CTA_text = "انتقل إلى الاستبيان")
#elseif($preferred_lang.equals("bg")) #set($lang_code = "BG") #set($CTA_text = "Към анкетата")
#elseif($preferred_lang.equals("ca")) #set($lang_code = "CA") #set($CTA_text = "Ves a l'enquesta")
#elseif($preferred_lang.equals("cs")) #set($lang_code = "CS") #set($CTA_text = "Vyplnit dotazník")
#elseif($preferred_lang.equals("da")) #set($lang_code = "DA") #set($CTA_text = "Åbn undersøgelsen")
#elseif($preferred_lang.equals("de")) #set($lang_code = "DE") #set($CTA_text = "Zur Umfrage")
#elseif($preferred_lang.equals("el")) #set($lang_code = "EL") #set($CTA_text = "Μετάβαση στην έρευνα")
#elseif($preferred_lang.equals("xa")) #set($lang_code = "XA") #set($CTA_text = "Ir a la encuesta")
#elseif($preferred_lang.equals("et")) #set($lang_code = "ET") #set($CTA_text = "Mine küsitluse juurde")
#elseif($preferred_lang.equals("fi")) #set($lang_code = "FI") #set($CTA_text = "Siirry kyselyyn")
#elseif($preferred_lang.equals("fr")) #set($lang_code = "FR") #set($CTA_text = "Accéder au sondage")
#elseif($preferred_lang.equals("he")) #set($lang_code = "HE") #set($CTA_text = "למילוי הסקר")
#elseif($preferred_lang.equals("hr")) #set($lang_code = "HR") #set($CTA_text = "Idi na anketu")
#elseif($preferred_lang.equals("hi")) #set($lang_code = "HI") #set($CTA_text = "सर्वे पर जाएं")
#elseif($preferred_lang.equals("hu")) #set($lang_code = "HU") #set($CTA_text = "Irány a kérdőív")
#elseif($preferred_lang.equals("id")) #set($lang_code = "ID") #set($CTA_text = "Buka survei")
#elseif($preferred_lang.equals("is")) #set($lang_code = "ISL") #set($CTA_text = "Taka könnun")
#elseif($preferred_lang.equals("it")) #set($lang_code = "IT") #set($CTA_text = "Vai al sondaggio")
#elseif($preferred_lang.equals("ja")) #set($lang_code = "JA") #set($CTA_text = "アンケートに回答する")
#elseif($preferred_lang.equals("ko")) #set($lang_code = "KO") #set($CTA_text = "설문조사 참여하기")
#elseif($preferred_lang.equals("lt")) #set($lang_code = "LT") #set($CTA_text = "Eiti į apklausą")
#elseif($preferred_lang.equals("lv")) #set($lang_code = "LV") #set($CTA_text = "Atvērt aptauju")
#elseif($preferred_lang.equals("ms")) #set($lang_code = "MS") #set($CTA_text = "Pergi ke tinjauan")
#elseif($preferred_lang.equals("nl")) #set($lang_code = "NL") #set($CTA_text = "Naar de enquête")
#elseif($preferred_lang.equals("no")) #set($lang_code = "NO") #set($CTA_text = "Åpne spørreundersøkelsen")
#elseif($preferred_lang.equals("pl")) #set($lang_code = "PL") #set($CTA_text = "Przejdź do ankiety")
#elseif($preferred_lang.equals("pt")) #set($lang_code = "PT") #set($CTA_text = "Ir para o questionário")
#elseif($preferred_lang.equals("ro")) #set($lang_code = "RO") #set($CTA_text = "Mergeți la chestionar")
#elseif($preferred_lang.equals("ru")) #set($lang_code = "RU") #set($CTA_text = "Перейти к опросу")
#elseif($preferred_lang.equals("sk")) #set($lang_code = "SK") #set($CTA_text = "Prejsť na dotazník")
#elseif($preferred_lang.equals("sl")) #set($lang_code = "SL") #set($CTA_text = "Pojdi na anketo")
#elseif($preferred_lang.equals("sr")) #set($lang_code = "SR") #set($CTA_text = "Otvori anketu")
#elseif($preferred_lang.equals("sv")) #set($lang_code = "SV") #set($CTA_text = "Fyll i enkäten")
#elseif($preferred_lang.equals("th")) #set($lang_code = "TH") #set($CTA_text = "ไปที่แบบสอบถาม")
#elseif($preferred_lang.equals("tr")) #set($lang_code = "TR") #set($CTA_text = "Ankete git")
#elseif($preferred_lang.equals("uk")) #set($lang_code = "UK") #set($CTA_text = "Перейти до опитування")
#elseif($preferred_lang.equals("vi")) #set($lang_code = "VI") #set($CTA_text = "Thực hiện khảo sát")
#elseif($preferred_lang.equals("ka")) #set($lang_code = "KAT") #set($CTA_text = "კითხვარზე გადასვლა")
#elseif($preferred_lang.equals("xb")) #set($lang_code = "PT-BR") #set($CTA_text = "Participar da pesquisa")
#elseif($preferred_lang.equals("tl")) #set($lang_code = "TGL") #set($CTA_text = "Pumunta sa survey")
#elseif($preferred_lang.equals("zh")) #set($lang_code = "ZH-S") #set($CTA_text = "前往问卷")
#elseif($preferred_lang.equals("xt")) #set($lang_code = "ZH-T") #set($CTA_text = "填寫問卷")
#elseif($preferred_lang.equals("es")) #set($lang_code = "ES-ES") #set($CTA_text = "Ir a la encuesta")
#else #set($lang_code = "EN") #set($CTA_text = "Go to survey")
#end

#set($final_url = $survey_link + $utms + $lang_code)
<a style="text-decoration: none; color: #ffffff; outline: none; font-weight: bold; padding: 12px 24px; display: inline-block;" href="$final_url" target="_blank">$CTA_text</a>

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Token Issue

You don’t actually need to build all the links like that if there’s only one link in the output!

 

The problem with multiple links in Velocity kicks in when you try to reuse the same variable name when building <a> tags. This includes loop variables, which have different values on every turn of the loop.

 

That’s why @Jo_Pitts1 and I always push people to use a config-first approach where things are stored in a single map variable. This works:

#set($surveyHostname = "example.com")

#set($queryPrefix = "?Q_id=${member.someField}&amp;Q_Language=")
#set($preferredLang = $lead.preferredLanguage)

#set( $languageMap = {
  "en-gb" : {
    "lang_code" : "EN-GB",
    "CTA_Text" : "Go to survey"
   },
   "ar" : {
     "lang_code" : "AR",
     "CTA_text" : "انتقل إلى الاستبيان"
    },
    "bg" : {
      "lang_code" : "BG",
      "CTA_text" : "Към анкетата"
     }
})
#set( 
  $linkNoProto = "${surveyHostname}${queryPrefix}${languageMap[$preferredLang]['lang_code']}" 
)
<a href="https://${linkNoProto}">${languageMap[$preferredLang]["CTA_text"]}</a>

 

View solution in original post

3 REPLIES 3
Crystal_Pacheco
Level 4

Re: Velocity Token Issue

Hi @SaurabhGoyal_GN 
This is a known issue with velocity tokens. You will need to output the entire <a> tag for each of the languages.
For example:

 

#if($preferred_lang.equals("en-gb"))
#set ($fullURL = '<a style="text-decoration: none; color: #ffffff; outline: none; font-weight: bold; padding: 12px 24px; display: inline-block;" href="https://samplelink.com/?Q_id={{member.Program_Level_field}}&amp;Q_Language=EN-GB" target="_blank">Go to survey</a>')
#elseif($preferred_lang.equals("ar"))
#set ($fullURL = '<a style="text-decoration: none; color: #ffffff; outline: none; font-weight: bold; padding: 12px 24px; display: inline-block;" href="https://samplelink.com/?Q_id={{member.Program_Level_field}}&amp;Q_Language=AR" target="_blank">انتقل إلى الاستبيان</a>')
#elseif ....

$fullURL

 



SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Token Issue

You don’t actually need to build all the links like that if there’s only one link in the output!

 

The problem with multiple links in Velocity kicks in when you try to reuse the same variable name when building <a> tags. This includes loop variables, which have different values on every turn of the loop.

 

That’s why @Jo_Pitts1 and I always push people to use a config-first approach where things are stored in a single map variable. This works:

#set($surveyHostname = "example.com")

#set($queryPrefix = "?Q_id=${member.someField}&amp;Q_Language=")
#set($preferredLang = $lead.preferredLanguage)

#set( $languageMap = {
  "en-gb" : {
    "lang_code" : "EN-GB",
    "CTA_Text" : "Go to survey"
   },
   "ar" : {
     "lang_code" : "AR",
     "CTA_text" : "انتقل إلى الاستبيان"
    },
    "bg" : {
      "lang_code" : "BG",
      "CTA_text" : "Към анкетата"
     }
})
#set( 
  $linkNoProto = "${surveyHostname}${queryPrefix}${languageMap[$preferredLang]['lang_code']}" 
)
<a href="https://${linkNoProto}">${languageMap[$preferredLang]["CTA_text"]}</a>

 

SaurabhGoyal_GN
Level 4

Re: Velocity Token Issue

Thanks @SanfordWhiteman for helping me here! Your solution makes a lot of sense.