Can you add script to a Marketo token? | Community
Skip to main content
Level 3
September 27, 2023
Solved

Can you add script to a Marketo token?

  • September 27, 2023
  • 2 replies
  • 2353 views

We have many landing pages where we have some custom script added in the LP: Custom HTML Head Section. 

Since we need to update these pages and the script would only be on selected LPs, not all,  looking at a way to do it via tokens. 

Can script be added in a Marketo token like a text token then the token be added to the Custom HTML Head section of the LP?

Are there limitations on lines of code in a Marketo token and what is the correct way to add it?

 

Thanks, 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Darshil_Shah1

I don't believe it's necessary to add JavaScript directly to the tokens as a matter of fact for its centralized management. You can simply load the JavaScript file in the Design Studio under 'Images and Files' and then just load the external JS file via the file's Design Studio URL on your landing page (you can place this in the 'Custom HTML Head' section). You can even add this at the template level if all the LPs created from it would need this. This way you'd not have to add the JS file to each LP page individually.

 

<script src="https://example.com/your-js-file.js"></script>

 

This is how users typically manage JavaScript that is used in multiple places, rather than adding it separately in the 'Custom HTML Head' section and then having to update it in each place individually.

2 replies

Darshil_Shah1
Community Advisor and Adobe Champion
Darshil_Shah1Community Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
September 27, 2023

I don't believe it's necessary to add JavaScript directly to the tokens as a matter of fact for its centralized management. You can simply load the JavaScript file in the Design Studio under 'Images and Files' and then just load the external JS file via the file's Design Studio URL on your landing page (you can place this in the 'Custom HTML Head' section). You can even add this at the template level if all the LPs created from it would need this. This way you'd not have to add the JS file to each LP page individually.

 

<script src="https://example.com/your-js-file.js"></script>

 

This is how users typically manage JavaScript that is used in multiple places, rather than adding it separately in the 'Custom HTML Head' section and then having to update it in each place individually.

LizNg2Author
Level 3
October 19, 2023

Hi Darshil - we attempted to save our JS file in Design Studio as you suggested and used the following script src format to serve it on individual LPs to test it out. When we added it to the LP Custom HTML Head section, it didn't seem to fire. But when we copied the JS as is directly into the section, it worked. Any advice on what we could be doing wrong, or if the order 

<script src="https://example.com/your-js-file.js"></script>

 

Darshil_Shah1
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
October 19, 2023

Did you verify this by checking the F12 Developer console? I'd usually check the Network tab to verify whether the request to the JS file was successful or not.

SanfordWhiteman
Level 10
September 28, 2023

Like Darshil says, the preferred way to insert JS is to

 

(a) use external JS files hosted in Design Studio

(b) embed them on the template, using a mktoBoolean to toggle them on/off per page

 

Using Custom Head HTML for per-page code, or putting code in a {{my.token}} that’s used on the page, simply doesn’t scale. It’s not that you’d run out of space in a {{my.token}}, it’s just a terrible way to store/serve code. Using Design Studio allows JS to be both cached by the browser and shared across pages.