SOLVED

Using lead tokens in javascript causing errors

Go to solution
Matt_Stone2
Level 9

Re: Using lead tokens in javascript causing errors

Hi Adam -- did Kenny's answer work for you? If not, you could try decoding each token individually up top, then using the decoded versions however you see fit.

So just above your code you'd have:

var product = "{{lead.primary-product}}";
var decodedProduct = $('<textarea/>').html(product).text();

var campaign = "{{lead.utm_campaign}}";
var decodedCampaign = $('<textarea/>').html(campaign).text();

var whatever = "{{lead.whateverToken}}";
var decodedWhatever = $('<textarea/>').html(whatever).text();

And then just use the decoded ones from then on. You can also use this setup to just output them individually as a test first.
Anonymous
Not applicable

Re: Using lead tokens in javascript causing errors

Hmm. 

Here is how that renders.

var adroll_custom_data = {
    "curCam": "Mobilizer_SNAP",
 "lastCam": $('<textarea/>').html(&#67;&#111;&#110;&#116;&#101;&#110;&#116;&#45;&#82;&#101;&#99;&#111;&#109;&#109;&#101;&#110;&#100;&#97;&#116;&#105;&#111;&#110;).text(),
 "prd": $('<textarea/>').html().text(),
 "inte": $('<textarea/>').html().text(),

....
}

Still with Escapes.

 
Kenny_Elkington
Marketo Employee

Re: Using lead tokens in javascript causing errors

Whoops, sorry, Adam.  You've got to add quotes those values so JS treats them as strings like:

$('<textarea/>').html("{{my.token}}").text()
Anonymous
Not applicable

Re: Using lead tokens in javascript causing errors

 "lastCam": $('<textarea/>').html("&#67;&#111;&#110;&#116;&#101;&#110;&#116;&#45;&#82;&#101;&#99;&#111;&#109;&#109;&#101;&#110;&#100;&#97;&#116;&#105;&#111;&#110;").text(),
 "prd": $('<textarea/>').html("").text(),
 "inte": $('<textarea/>').html("").text(),



Cool. No change with quotes. 😞
Matt_Stone2
Level 9

Re: Using lead tokens in javascript causing errors

Did you try decoding them in advance as individual variables like I showed above?