SOLVED

Tokenized mailto link in landing page?

Go to solution
Jroscoe
Level 2

Tokenized mailto link in landing page?

Hi - not sure if this is possible, but I'd like to have a mailto link open up from a landing page and have that link populate the send to email address from the {{lead.Lead Owner Email Address}}. 

 

Basically the call to action is contact your rep, and by clicking the link it opens an email addressed to the record owner. 

 

Is this possible?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Tokenized mailto link in landing page?

Of course. But you have to use the proper encoding, so don’t put the token directly into the href.  Use the function from here to output into a <datalist> first and read it out:

<datalist class="mktoTokens">
<option label="lead.Email Address">{{lead.Lead Owner Email Address}}</option>
</datalist>
<a id="contact-rep">Contact your rep</a>

<script>
function getExportedMktoTokens(tokenLabels){
   
   const stor = "datalist.mktoTokens option[label]";     
   const options = Array.from(document.querySelectorAll(stor));

   const ignoreCaseComparator = Intl.Collator(undefined, { sensitivity: "accent" });
   
   let results = [];
   for( const name of [tokenLabels].flat() ){ 
      const value = options.find( option => ignoreCaseComparator.compare(option.label, name) === 0 )?.value;
      results.push(value ?? null);
   }

   return Array.isArray(tokenLabels) ? results : results[0];
}

let leadEmailAddress = getExportedMktoTokens("lead.Email Address");
let contactRepLink = document.querySelector("#contact-rep");
contactRepLink.href = "mailto:" + encodeURIComponent(leadEmailAddress);
</script>

 

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Tokenized mailto link in landing page?

Of course. But you have to use the proper encoding, so don’t put the token directly into the href.  Use the function from here to output into a <datalist> first and read it out:

<datalist class="mktoTokens">
<option label="lead.Email Address">{{lead.Lead Owner Email Address}}</option>
</datalist>
<a id="contact-rep">Contact your rep</a>

<script>
function getExportedMktoTokens(tokenLabels){
   
   const stor = "datalist.mktoTokens option[label]";     
   const options = Array.from(document.querySelectorAll(stor));

   const ignoreCaseComparator = Intl.Collator(undefined, { sensitivity: "accent" });
   
   let results = [];
   for( const name of [tokenLabels].flat() ){ 
      const value = options.find( option => ignoreCaseComparator.compare(option.label, name) === 0 )?.value;
      results.push(value ?? null);
   }

   return Array.isArray(tokenLabels) ? results : results[0];
}

let leadEmailAddress = getExportedMktoTokens("lead.Email Address");
let contactRepLink = document.querySelector("#contact-rep");
contactRepLink.href = "mailto:" + encodeURIComponent(leadEmailAddress);
</script>

 

JustinTy
Level 2

Re: Tokenized mailto link in landing page?

Yes, this is possible—as long as the person viewing the landing page is a known lead.

 

You can use a mailto: link like this:

mailto:{{lead.Lead Owner Email Address}}?subject=Let’s%20Connect&body=Hi%20there,%20I’d%20like%20to%20get%20in%20touch...

 

This will open the user’s email client and pre-fill the “To” field with the lead owner’s email, as long as Marketo can resolve the token at the time of page load.

 

Important:

This only works if the lead is known—meaning they’ve previously filled out a form or clicked through from a Marketo email, so their cookie is associated. If the lead is anonymous or the Lead Owner Email Address field is empty, the token won’t resolve, and the link will break or appear blank.

 

If you’re worried about unknown visitors, consider linking to a general contact form or rep directory as a fallback.

SanfordWhiteman
Level 10 - Community Moderator

Re: Tokenized mailto link in landing page?

@JustinTy you can’t output the raw token like that, as I mentioned.

 

You must use the method in my post (output in <datalist>, read it from there, and URL-encode), because lead tokens are not URL-encoded and the mailto: may include characters that require URL-encoding.