SOLVED

Email ID as query string parameter

Go to solution
jamespapke
Level 1

Email ID as query string parameter

Hello all - I can't seem to find this answer, so any help is appreciated. I'd like to automatically append the email id (marketo asset email id) to a query string parameter. As it's not available in the field list when creating an Email Script token, does that mean it's impossible? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Email ID as query string parameter

You can use the code here (which should be cross-posted to the official Products blog but I haven’t gotten around to it!).

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Email ID as query string parameter

You can use the code here (which should be cross-posted to the official Products blog but I haven’t gotten around to it!).

jamespapke
Level 1

Re: Email ID as query string parameter

Thank you, @SanfordWhiteman! I can't say I know exactly how this works even having ChatGPT explain it to me haha.  But with limiting the printed value to ${marketoSend.AssetId}, this works perfectly. 

SanfordWhiteman
Level 10 - Community Moderator

Re: Email ID as query string parameter

There is quite a lot of special sauce in there for sure.

jamespapke
Level 1

Re: Email ID as query string parameter

I've hit a bump in the road and would love to know if what I'm doing is achievable. 

I've modified the script to have some text before and after the email id, and set this as a folder token as "{{my.utm source medium content}}". I combine this token with "{{my.utm campaign}}" which is a local text token used in the Program and create a URL as 'https://example.com?{{my.utm source medium content}}{{my.utm campaign}}'. The output would look like this: 

https://example.com?utm_medium=email&utm_source=marketo&utm_content=99999&utm_campaign=test_campaign

This works as expected in the email preview, and when the email is sent BUT ONLY when the link is not tracked. When the link is tracked, the email script is written in full in the place of the {{my.utm source medium content}} token,

<a href="example.com?{{my.utm source medium content}}{{my.utm campaign}}" target="_blank">HYPERLINK TEXT</a>
turns into this: 
https://www.example.com/?&mkt_tok=MjgwLVFESy0yMTUAAAGS_MzEaudY6U_C7CICOrqn9-0QWoUXLqnVQJwNjMGngtk4Ka...

Disabling the mkt_tok does not remedy the issue, though I would not want to disable this anyway. 

I've gone through this lengthy post and am hoping what I am trying to do is still possible!
EDIT: I am now also seeing this, which suggests my plan is not possible. A helper field would not be able to access the specific email being sent like the workaround suggests Email Script Token Not Resolving in a URL Link - Marketing Nation (marketo.com)

Thank you for anyone taking the time to look at this 🙂, especially @SanfordWhiteman!

 

Token Script for {{my.utm source medium content}}:

 

 

 

#set ($utm_text = "utm_medium=email&utm_source=marketo&utm_content=")
#set ($utm_campaign_text = "&utm_campaign=")
#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

${utm_text}${marketoSend.AssetId}${utm_campaign_text}