Hi Team,
I’m trying to understand two things:
The Use of My Tokens versus Lead Tokens in Marketo.
How to use a Velocity script to handle a field in Marketo that contains a full URL.
1. The Use of My Tokens versus Lead Tokens in Marketo.
We have a string field in Marketo called Referral Code, and we need to append this value dynamically within a URL in our emails.
Initially, I tried using a My Token (with an email script inside it) and then referenced that token in the URL. While the value appeared correctly in Preview, the actual test send did not resolve the referral code — instead, the literal token ({{my.TokenName}}) appeared in the final URL.
I found that adding class="mktNoTrack" allows the My Token to render correctly inside the link, but it also makes the URL untracked, which we want to avoid.
Recently, I tested using the lead-level token directly in the URL (e.g., {{lead.Referral Code}}). This worked correctly — the URL resolved as expected and the click was fully tracked in Marketo reports.
I’m seeing the same behavior with Custom Object fields:
When used inside a My Token → link breaks unless we disable tracking
When used directly in the URL → link works and stays trackable
So I wanted to understand why placing a field inside a My Token and then using that token in a URL behaves differently compared to using a lead token directly.
2. How to use a Velocity script to handle a field in Marketo that contains a full URL.
We have a field in Marketo that stores a full URL, but when used as a token it isn’t tracked. Our long-term plan is to sync the field from CRM without the http/https, then prepend it in the email so tracking works.
In the meantime, I tested a Marketo-only solution using Velocity to strip the https from the URL. I found this document which was helpful but there is some issue i faced while testing https://nation.marketo.com/t5/product-discussions/trim-http-or-https-from-field-value-via-velocity-o...
#set( $fieldWithScheme = $lead.marketingOwnerMSBooking )
#if( $fieldWithScheme && $fieldWithScheme.trim() != "" )
#set( $fieldWithoutScheme = $fieldWithScheme.replaceAll("^https://","") )
${fieldWithoutScheme}#
else
outlook.office365.com/book/BFCFinConsultant-Bookings@LBED.onmicrosoft.com/s/EGn2yKIMfUO09ZSFJQ-jSw2#
end
In the preview, the Velocity output worked correctly, but when I sent a live test email the link didn’t resolve. In the activity log, Marketo logged the literal Velocity token output instead of the fully rendered link. So even though it appeared to work in preview, the live send didn’t process the Velocity token the same way, which caused the link to break.
Not sure what went wrong here, but the link didn’t work in the live test and wasn’t tracked. Need guidance on how to make the whole URL within a token to work using velocity script and also to make it trackable.
Do let me in case if you need anything else
Regards,
Akshat
Solved! Go to Solution.
Also note the Velocity code you posted has fatal syntax errors. There’s no way it ran like that (missing leading # in 2 places).
@SanfordWhitemanI tried again this morning but wasn’t able to identify the issue. Could you please help me correct the error? I’ve been working on it, but I’m not sure what I might be missing, so your assistance would be greatly appreciated.
I’m trying to track a field that contains a full URL by removing the https outside of the token (as mentioned above) and ensuring the link remains trackable within Marketo.
Velocity :
#set( $fieldWithScheme = $lead.marketingOwnerMSBooking )
#if( $fieldWithScheme && $fieldWithScheme.trim() != "" )
#set( $fieldWithoutScheme = $fieldWithScheme.replaceAll("^https://","") )
${fieldWithoutScheme}
#else
outlook.office365.com/book/BFCFinConsultant-Bookings@LBED.onmicrosoft.com/s/EGn2yKIMfUO09ZSFJQ-jSw2
#end
This is how the token having the velocity script is been added
Do let me know if you need anything else !!
Regards,
Akshat
When posting code, you must use the syntax highlighter (“Insert/Edit Code Sample”) for it to be readable.
In any case, you must output the entire <a> tag (through closing </a>) from Velocity for this to work, as noted in many earlier threads.
Thanks for sharing your feedback earlier. I’ve tested it , and I can confirm that it works correctly and is trackable—much appreciated.
I have another question regarding this:
When I add a lead token directly to a URL, it works fine and remains trackable, for example: https://www.google.com/?{{lead.refcode}}
However, when I try to add the same lead field via a My Token like this: https://www.google.com/{{my.ref-code}}
It's not that a My Token isn't trackable when used in https://www.google.com/{{my.ref-code}}. But it can't be a Script Token. Script Tokens - which are a subclass of Program Tokens or My Tokens - need to output a string from <a> to </a>. Text Tokens don't need to.
Thanks @Michael_Florin that worked as expected .
Really appreciate yours and @SanfordWhiteman help on this !!
This should help you:
https://blog.teknkl.com/use-velocity-to-track-links-with-protocol-included/