HI @SanfordWhiteman & @Jo_Pitts1,
thank you very much for your replies, I appreciate you taking the time. I believe I have achieved partial success in that I can now reference the values set in the first email script token in the second email script token and use those values to create a HTML block that can then be added dynamically into the email - see below:
1st Email script token - {{my.Product-Preference-URLs}} - set as follows:
#set ( $productPreferenceURLs = {
"ProductCode1" : "https://www.webpage1.com/",
"ProductCode2" : "https://www.webpage2.com/",
"ProductCode3" : "https://www.webpage3.com/",
"ProductCode4" : "https://www.webpage4.com/",
"ProductCode5" : "https://www.webpage5.com/",
} )
2nd Email script token - {{my.Fund-Preferences}} - set as follows:
## Extract the Product URLs array from the $productPreferenceURLs variable in the {{my.Product-Preference-URLs}} Email Script Token
#set( $referenceURLs = ${productPreferenceURLs} )
## Set a counter to limit the number of products displayed in the email
#set( $counter = 0 ) ## Initialize a counter
#if( $Product_Preference__cList && $Product_Preference__cList.size() > 0 )
#foreach( $product in $Product_Preference__cList )
## Set Product ID and Product Name variables
#set( $productID = $product.Product__cList.get(0).Product_ID__c )
#set( $productName = $product.Product__cList.get(0).Name )
#foreach( $key in $referenceURLs.keySet() )
#if( $key.equals($productID) )
#set( $url = ${referenceURLs.get($key)} )
#break
#else
#set( $url = "https://www.webpagehome.com/" )
#end
#end
## Check if the counter is less than 5
#if( $counter < 5 )
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" valign="top" style="border-top:solid 2px #d9d9d9; padding: 10px 0 10px 0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" valign="top" width="57">
<a href="$url?utm_source={{my.UTM-Source}}&utm_medium={{my.UTM-Medium}}&utm_campaign={{my.UTM-Campaign}}" target="_blank">
<img src="http://munchkinID.mktoweb.com/rs/munchkinID/images/icons-pdf-download.gif" width="42" height="40" alt="PDF" style="display:block; border:0; outline:none; text-decoration:none; -ms-interpolation-mode:bicubic;" />
</a>
</td>
<td align="left" valign="top" class="body-l" style="font-family:Poppins, Arial, sans-serif; font-size:16px; line-height:24px; mso-line-height-rule:exactly; font-weight:700; color:#16293F; text-align:left; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; mso-table-lspace:0pt; mso-table-rspace:0pt; word-break:break-word; hyphens:none; -webkit-hyphens:none; -moz-hyphens:none; padding-top: 2px">
<a href="$url?utm_source={{my.UTM-Source}}&utm_medium={{my.UTM-Medium}}&utm_campaign={{my.UTM-Campaign}}" target="_blank" style="font-weight:700; color:#16293F; text-decoration:none">
$productName
</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
## Increment the counter
#set( $counter = $counter + 1 )
#else
## Stop the loop when 5 product preferences have been displayed
#break
#end
#end
#else
#set( $productID = "NUFP" )
#set( $productName = "No Company Product Preferences" )
## Set URL
#set( $url = "https://www.webpagehome.com/" )
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" valign="top" style="border-top:solid 2px #d9d9d9; padding: 10px 0 10px 0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" valign="top" width="57">
<a href="$url?utm_source={{my.UTM-Source}}&utm_medium={{my.UTM-Medium}}&utm_campaign={{my.UTM-Campaign}}" target="_blank">
<img src="http://munchkinID.mktoweb.com/rs/munchkinID/images/icons-pdf-download.gif" width="42" height="40" alt="PDF" style="display:block; border:0; outline:none; text-decoration:none; -ms-interpolation-mode:bicubic;" />
</a>
</td>
<td align="left" valign="top" class="body-l" style="font-family:Poppins, Arial, sans-serif; font-size:16px; line-height:24px; mso-line-height-rule:exactly; font-weight:700; color:#16293F; text-align:left; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; mso-table-lspace:0pt; mso-table-rspace:0pt; word-break:break-word; hyphens:none; -webkit-hyphens:none; -moz-hyphens:none; padding-top: 2px">
<a href="$url?utm_source={{my.UTM-Source}}&utm_medium={{my.UTM-Medium}}&utm_campaign={{my.UTM-Campaign}}" target="_blank" style="font-weight:700; color:#16293F; text-decoration:none">
$productName
</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
#end
The email references both tokens as follows:
When I Preview or Send a Sample of the email, then the URLs are rendered as expected, e.g. https://www.webpagehome.com/?utm_source={{my.UTM-Source}}&utm_medium={{my.UTM-Medium}}&utm_campaign=...}}
However, if I execute the email then the received link is as shown below and when clicked, this resolves to the 2nd URL:
As you can see, the literal $url variable is displayed rather than the expected URL as per the Preview and Send Sample tests. Can you explain why this is occurring and what should be done to ensure the URL renders as expected please?
Regards
You shouldn’t use curly braces/formal references inside directives, like you’re doing here:
#set( $referenceURLs = ${productPreferenceURLs} )
Formal refs are only necessary inside strings. In other cases they can break parsing, i.e. ${object}.property
will not work but $object.property
will.
In any case, your problem is reusing the same top-level object with different string properties, as opposed to using distinct top level strings. Marketo’s Velocity “uberspector“, which pre-processes URLs to make them trackable, requires distinct variables. You can set the link to not trackable (add class="mktNoTrack"
) to test the difference.
Hi @SanfordWhiteman,
thank you for your reply, I'm pleased to report that the suggestion to add class="mktNoTrack" has worked and the URL value is being output in the email now rather than the literal variable.
As it's not ideal to remove tracking for these URLs, I've found one of your blogs - https://blog.teknkl.com/multiple-marketo-tracked-links-in-velocity/amp/ - which outlines a solution to the overcoming the re-use of the same top-level object. Would you recommend this approach still or have you an alternative solution to the issue?
In the meantime, I have a further problem that I wish to overcome in relation to the above requirement. I have 3 further Text Program tokens that are used to set UTM values - {{my.UTM-Campaign}}, {{my.UTM-Source}}, & {{my.UTM-Medium}} - and each token contains a string value, e.g. em_20241113, mkto & email-organic.
These tokens are used elsewhere within the email content but I would also like to utilise them in the Email Script token discussed in this thread.
How should I reference these tokens within the Email Script token. I am currently hard-coding the values as follows and this method works when I use those variable further into the script to construct the appended UTM string:
## Set UTM values from Program tokens
#set( $utmSource = "marketo" )
#set( $utmMedium = "email-organic" )
#set( $utmCampaign = "em-reports")
## Set URL
#set( $uRLFull = "www.webpage.com/" )
#set( $uRLUTM = "?utm_source=${utmSource}&utm_medium=${utmMedium}&utm_campaign=${utmCampaign}" )
#set( $uRLBuild = "${uRLFull}${uRLUTM}" )
<a href="https://${uRLBuild}" target="_blank" style="font-weight:700; color:#16293F; text-decoration:none">
I have attempted the following approaches to retrieve the token values from the Text Program tokens but to no avail:
## 1st Attempt - Failed
#set( $utmSource = ${my.UTM-Source} )
#set( $utmMedium = ${my.UTM-Medium} )
#set( $utmCampaign = ${my.UTM-Campaign})
## 2nd Attempt - Failed
#set( $utmSource = $my.UTM-Source )
#set( $utmMedium = $my.UTM-Medium )
#set( $utmCampaign = $my.UTM-Campaign)
## 3rd Attempt - Failed
#set( $utmSource = {{my.UTM-Source}} )
#set( $utmMedium = {{my.UTM-Medium}} )
#set( $utmCampaign = {{my.UTM-Campaign}} )
Could you please advise on how I can correctly reference the 3 text Program tokens within the Email Script token?
Regards
Hi @SanfordWhiteman,
thank you for confirming and for all your assistance. Thank you also to @Jo_Pitts1 for your feedback.
As suggested, I have created a new ticket for how to use Text tokens in a Email Script token - 'Referencing Program Token in Email Scripting Token'.
I'm hoping to continue developing the email script token we've discussed in this thread to overcome the looping issue and will post a further update when I have more to report.
Regards