Dear all,
we have the following code in a velocity token:
#set($downloadLink={
"BPDCS":{
"title":"BPD Case Study",
"link":"infos.inficiences.com/rs/593-IYJ-660/images/Inficiencespartners-casestudy-bpd-digitalisation-marketing-systeme-information-marketing-commercial.pdf"
},
"DACS":{
"title":"Deny All Case Study",
"link":"infos.inficiences.com/rs/593-IYJ-660/images/Inficiencespartners-casestudy-denyall-marketing-automation.pdf"
},
"IVCS":{
"title":"Infovista Case Study",
"link":"infos.inficiences.com/rs/593-IYJ-660/images/Inficiencespartners-casestudy-infovista-systeme-information-marketing.pdf"
},
"EBSCS":{
"title":"ESSEC Case Study",
"link":"infos.inficiences.com/rs/593-IYJ-660/images/Inficiencespartners-casestudy-essec-conception-deploiement-strategie-acquisition-nurturing.pdf"
},
"KDSCS":{
"title":"KDS Case Study",
"link":"infos.inficiences.com/rs/593-IYJ-660/images/Inficiencespartners-casestudy-kds-nouvelles-pratiques-generation-demande-automatisee.pdf"
}
})
<ul>
#foreach ($key in $lead.downloadcenter.split("[;]"))
#set ($key = ${key.trim()})
<li><a href="http://${downloadLink.get($key).link}" target="_blank" class="mktNoTrack">$downloadLink.get($key).title</a></li>
#end
</ul>
It works well. But if we remove the class="mktNoTrack" from the <a> tag, the links generated raise a DNS error:
any hint ?
-Greg
Solved! Go to Solution.
Are you following what's at the bottom of this doc? http://developers.marketo.com/email-scripting/ Link tracking doesn't work in a foreach loop which I think is what you have your links printing in if I'm reading it correctly.
This is what I read in the doc:
To ensure proper parsing of URLs, the whole path should be set as a variable and then printed, and variable should not be printed inside of URL references. The protocol(http:// or https://) must be included and must be separate from the rest of the URL.
Which is why in the code reads
href="http://${downloadLink.get($key).link}"
and indeed:
Links will not be tracked if they are outputted from within a for or foreach loop.
but for the moment, it does not seem to be a tracking problem, but rather than the {downloadLink.get($key).link} is not rendering. Now, if the loop is the issue, then I suppose I will have no choice but use a webhook to create the list of links, send it back to a field and output it directly in the email.
-Greg
I've got your solution -- just wait up a bit..
Hi Sanford Whiteman ,
I have tested the code from the blog and this is the email, with different values selected in the form:
It renders the 1st one 4 times
-Greg
That exact code is clipped from my primary instance. Resulting links are:
PS: can it be because the variable velocityCount
is not incremented ?
-Greg
PS: can it be because the variable
velocityCount
is not incremented ?
$velocityCount is automatically created and incremented.
Maybe there's something different in your instance. Try $foreach.count instead of $velocityCount.
... full line being
#evaluate( "${esc.h}set( ${esc.d}downloadLink_${foreach.count} = ${esc.d}downloadLink )" )
Hi again Sanford,
My bad. If velocity count was not incremented, downloadink_2 and above would be empty.
Here, the output seems not to find any other value than the first one (downloadLink_1) and repeat it for each item.
-Greg
I tried this code:
#foreach( $key in $lead.downloadcenter.split(";") )
#set( $downloadLink = $allDownloadLinks[$key] )
${downloadLink.text}</br>
#evaluate( "${esc.h}set( ${esc.d}downloadLink_${velocityCount} = ${esc.d}downloadLink )" )
#end
and it is rendering
IV Case Study
IV Case Study
-Greg
On the assumption that your instance is configured differently please try this code instead (replacing the code after the dict of course):
#foreach( $key in $lead.downloadcenter.split(";") )
#set( $downloadLink = $allDownloadLinks[$key] )
#evaluate( "${esc.h}set( ${esc.d}downloadLinkHref_${foreach.count} = ${esc.d}downloadLink.href )" )
#evaluate( "${esc.h}set( ${esc.d}downloadLinkText_${foreach.count} = ${esc.d}downloadLink.text )" )
#end
#if( $downloadLinkHref_1 )
<a href="http://${downloadLinkHref_1}" target="_blank">${downloadLinkText_1}</a>
#end
#if( $downloadLinkHref_2 )
<a href="http://${downloadLinkHref_2}" target="_blank">${downloadLinkText_2}</a>
#end
#if( $downloadLinkHref_3 )
<a href="http://${downloadLinkHref_3}" target="_blank">${downloadLinkText_3}</a>
#end
#if( $downloadLinkHref_4 )
<a href="http://${downloadLinkHref_4}" target="_blank">${downloadLinkText_4}</a>
#end
#if( $downloadLinkHref_5 )
<a href="http://${downloadLinkHref_5}" target="_blank">${downloadLinkText_5}</a>
#end
Grégoire Michel what about the string-only approach (the 2nd one above) in your instance? Don't keep me in suspense!
Hi Sanford,
awfully busy, I haven't had time to test yet. Of course, I'll let you know.
-Greg
Hi Sanford,
Is there a way to store the dictionary outside of the Velocity script, in a place where it would be easily maintained?
-Greg
You can store the variable in a separate token (which I recommend for data dicts like this) and include it in the <head> of your templates.
But you can't read directly from anywhere but the Velocity context. You can use a separate app to periodically copy data from a text file into a token, but that's creating some moving parts. Doable, though.
Really cool. Thx
-Greg
AFAIK not so much the #foreach as the final output containing multiple links and wrapping in <li>s (that's why I asked Greg to reduce it to 1).
This is known behavior that I posted a workaround for before...
Hi Sanford,
I do not know what would be the outcome if we changed the code, but if we select only 1 doc in the form, we get only 1 <a> and it still breaks. But it still goes through the loop.
My velocity skills are not good enough to be able to change the code so that only the first value is used outside of the look.
-Greg