Velocity Scripting with Segmentation

Catalin
Level 1

Velocity Scripting with Segmentation

Hi,

 

I have this velocity working with segmentation. I'm able to get the first baseUrl populated, however the second baseUrl1 is not working. This is how it displays:  https://${url}/ 

 

 

#set( $AssetId = $mktmail.xMarketoIdHdr.split(":")[5] )
#set($utm_campaign = "utm_campaign=" + $esc.url($AssetId))
#set($utm_source="Nurture")
#set($utm_content="ABC")
#set($utm_term="CDE")
#set($utm_id = "utm_id=EFG")

#set($baseUrl = "www.abc.com?formid=001&utm_medium=Email&utm_source=$utm_source&utm_content=$utm_content&utm_term=$utm_term")
#set($baseUrl1= "www.abc.com?formid=002&utm_medium=Email&utm_source=$utm_source&utm_content=$utm_content&utm_term=$utm_term")

#if($lead.Segmentation_Test_1000.equals("Stuff"))
    #set($url = $baseUrl+"&"+ $utm_campaign + "&" + $utm_id)
#elseif($lead.Segmentation_Test_1000.equals("Other Stuff"))
    #set($url = $baseUrl1+"&"+ $utm_campaign + "&" + $utm_id)
#end

 

 

I've also tried including https:// protocol as well and still not working

Do you know what the reason might be? Thanks

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting with Segmentation

You’re likely running into known behavior of the Velocity Introspector when reusing using the same $variable.

 

Try it like this instead (also fixing up some variable names that were semantically inconsistent):

#set($AssetId = $mktmail.xMarketoIdHdr.split(":")[5] )
#set($utm_campaign = $esc.url($AssetId))
#set($utm_source = "Nurture")
#set($utm_content = "ABC")
#set($utm_term = "CDE")
#set($utm_id = "EFG")
#set($baseUrlsBySegmentation = {
  "Stuff": "www.abc.com?formid=0001",
  "Other Stuff": "www.abc.com?formid=0002"
})
#set($url = $baseUrlsBySegmentation[$lead.Segmentation_Test_1000] +
  "utm_medium=Email" +
  "utm_campaign=${utm_campaign}"
  "utm_source=${utm_source}" +
  "utm_content=${utm_content}" +
  "utm_term=${utm_term}" +
  "utm_id=${utm_id}"
)
<a href="https://${url}">Go</a>

 

 

Catalin
Level 1

Re: Velocity Scripting with Segmentation

Thank you, Sanford.

 

Good point, but it still didn't work. Since this was quite urgent, I went with one token per each segment, so I created two tokens. Luckily for me I only had two segments, but I'm still curious to solve this, as maybe in the future the segmentation will have 10-15 segments, and I need to find a solution for doing this in one token.