I've built an email where most of the content is generated inside of a script token. This token uses a For Loop (and information from the customer's profile) to generate a bunch of CTA's that the customer can click on. This all works fine; I just needed to explain that the For Loop inside the token is vital to the email's construction.
Here's the problem: The CTA's created inside of this loop needs to pass the customer's Marketo ID as a way to identify them(something like "website.com/?mID=(Marketo ID"). I found that I can drop {{Lead.ID}} straight into the email body and it will display the number no problem. However, using that same code inside a token doesn't work. The result is "website.com/?mID={{Lead.ID}}".
Next I tried declaring it as a variable inside of a token. I check the box next to "Marketo ID", wrote "#set( $m_ID = ${lead.marketoID}) at the top of my token, and then wrote the URL into the token as "website.com/?mID=${m_ID}." The end result is the link looking like "website.com/?mID=" with no ID or even the variable name.
It seems silly to me that there wouldn't be a way to include Marketo ID in a token, but I just can't find a way to do it. Is there a way to do what I'm describing? If there's a better way to ID someone via a URL parameter for use on another website, I'm all ears.
Solved! Go to Solution.
Next I tried declaring it as a variable inside of a token. I check the box next to "Marketo ID", wrote "#set( $m_ID = ${lead.marketoID}) at the top of my token, and then wrote the URL into the token as "website.com/?mID=${m_ID}." The end result is the link looking like "website.com/?mID=" with no ID or even the variable name.
Don’t think that field is a standard field. It’s probably custom if you look in Field Management. Perhaps it was intended to mirror the Lead ID (via Change Data Value) but the corresponding smart campaign wasn’t set up.
In any case, setting an intermediate variable will never change anything. If the right-hand side of a #set
exists, you could use also that expression directly; if not, you can’t make it exist.
Anyway, here’s how to get more information about the send context, including the Lead ID. Pretty sure this still works:
#set( $marketoSend = {} )
#set( $delim = ":|-" )
#set( $values = $mktmail.xMarketoIdHdr.split($delim) )
#set( $numParts = $values.size() )
## Campaign Run ID not relevant in Preview, Test Variant not always present, etc.
#set( $keyTemplatesBySize = {
13 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId--TestVariantId",
12 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId-",
11 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId",
"*" : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::LeadId"
} )
#set( $marketoIdKeys = $display.alt($keyTemplatesBySize[$numParts],$keyTemplatesBySize["*"]) )
#set( $keys = $marketoIdKeys.split($delim) )
## loop interesting keys
#foreach( $key in $keys )
#if( !$key.isEmpty() )
#if( $key.startsWith("+") )
#set( $finalKey = $key.substring(1) )
#set( $marketoSend[$finalKey] = $marketoSend[$finalKey] + "-" + $values[$foreach.index] )
#else
#set( $finalKey = $key )
#set( $marketoSend[$finalKey] = $values[$foreach.index] )
#end
#end
#end
Munchkin ID is ${marketoSend.MunchkinId}
Campaign ID is ${marketoSend.CampaignId}
Campaign Run ID is ${marketoSend.CampaignRunId}
Step ID is ${marketoSend.StepId}
Asset ID is ${marketoSend.AssetId}
Lead ID is ${marketoSend.LeadId}
Test Variant ID is ${marketoSend.TestVariantId}
Next I tried declaring it as a variable inside of a token. I check the box next to "Marketo ID", wrote "#set( $m_ID = ${lead.marketoID}) at the top of my token, and then wrote the URL into the token as "website.com/?mID=${m_ID}." The end result is the link looking like "website.com/?mID=" with no ID or even the variable name.
Don’t think that field is a standard field. It’s probably custom if you look in Field Management. Perhaps it was intended to mirror the Lead ID (via Change Data Value) but the corresponding smart campaign wasn’t set up.
In any case, setting an intermediate variable will never change anything. If the right-hand side of a #set
exists, you could use also that expression directly; if not, you can’t make it exist.
Anyway, here’s how to get more information about the send context, including the Lead ID. Pretty sure this still works:
#set( $marketoSend = {} )
#set( $delim = ":|-" )
#set( $values = $mktmail.xMarketoIdHdr.split($delim) )
#set( $numParts = $values.size() )
## Campaign Run ID not relevant in Preview, Test Variant not always present, etc.
#set( $keyTemplatesBySize = {
13 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId--TestVariantId",
12 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId-",
11 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId",
"*" : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::LeadId"
} )
#set( $marketoIdKeys = $display.alt($keyTemplatesBySize[$numParts],$keyTemplatesBySize["*"]) )
#set( $keys = $marketoIdKeys.split($delim) )
## loop interesting keys
#foreach( $key in $keys )
#if( !$key.isEmpty() )
#if( $key.startsWith("+") )
#set( $finalKey = $key.substring(1) )
#set( $marketoSend[$finalKey] = $marketoSend[$finalKey] + "-" + $values[$foreach.index] )
#else
#set( $finalKey = $key )
#set( $marketoSend[$finalKey] = $values[$foreach.index] )
#end
#end
#end
Munchkin ID is ${marketoSend.MunchkinId}
Campaign ID is ${marketoSend.CampaignId}
Campaign Run ID is ${marketoSend.CampaignRunId}
Step ID is ${marketoSend.StepId}
Asset ID is ${marketoSend.AssetId}
Lead ID is ${marketoSend.LeadId}
Test Variant ID is ${marketoSend.TestVariantId}
Oh wow, that did the trick! I swear, it's never straight forward to do the things I want in Marketo.
Thanks SanfordWhiteman! Your knowledge is always appreciated. For real though, Adobe should pay you to rewrite all of their documentation. Whenever I can't find an answer there, it seems you've already figured it out here.
The tricks are the trade, yes!
It would appear I spoke to soon. Earlier, when I said it was working, I was just doing a preview view of the email in question, adding my own email address so my Marketo ID popped up. Mousing over the link in the preview window showed the appropriate URL (www.website.com/?m_id=12736459).
Afterwards, I did a more thorough test. I took the code for your token and altered it so that after the last "end" in the code, all that remained was ${marketoSend.LeadId}, hoping it would simply print that value:
#set( $marketoSend = {} )
#set( $delim = ":|-" )
#set( $values = $mktmail.xMarketoIdHdr.split($delim) )
#set( $numParts = $values.size() )
## Campaign Run ID not relevant in Preview, Test Variant not always present, etc.
#set( $keyTemplatesBySize = {
13 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId--TestVariantId",
12 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId-",
11 : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::CampaignRunId:LeadId",
"*" : "MunchkinId-+MunchkinId-+MunchkinId::CampaignId:StepId::AssetId::LeadId"
} )
#set( $marketoIdKeys = $display.alt($keyTemplatesBySize[$numParts],$keyTemplatesBySize["*"]) )
#set( $keys = $marketoIdKeys.split($delim) )
## loop interesting keys
#foreach( $key in $keys )
#if( !$key.isEmpty() )
#if( $key.startsWith("+") )
#set( $finalKey = $key.substring(1) )
#set( $marketoSend[$finalKey] = $marketoSend[$finalKey] + "-" + $values[$foreach.index] )
#else
#set( $finalKey = $key )
#set( $marketoSend[$finalKey] = $values[$foreach.index] )
#end
#end
#end
${marketoSend.LeadId}
I then dropped this token into the body of my email, sent it to myself, and it printed my Marketo ID perfectly as text.
Next, I dropped that same slightly modified token into a URL so it looked like this:
<a href="https://www.website.com/?m_id={{my.Test_mID}}">
However, when I sent myself an email with this code, the link looked like this:
"www.website.com/?m_id=&mkt_tok=MDkyLU1W..."
After the elipsis there was a long string of characters, and after all of that, I noticed it inserted ALL of the code from inside the {{me.Test_mID}} token. In an attempt to fix this, I rewrote the token slightly so after the last "end" in, it said:
#set ($mID = $marketoSend.LeadId )
After inserting this new token into the email, I also updated the relevant part of the URL to say "...?m_ID={{mID}}". Finally, I sent the email to myself one last time. Here's what the URL returned this time:
www.website.com/?m_id=${mktmail.vMID_7}
So, I can get my Marketo ID to print inside of the email, but NOT as a URL parameter. Any idea where I might have gone wrong here?
You have to output the whole <a> from Velocity (this isn't specific to the current use case).