Skip to content

✏️ Earn 6 months of Premium for your first approved article. Register.

Use client-side JavaScript in content block
831 views

Use client-side JavaScript in content block

View favourites

Recently, I attempted to reference a content block from a cloud page that contained client-side JavaScript, and to my surprise, Salesforce Marketing Cloud removed it entirely. It looks like certain hook that triggers when you save your content block doesn;t like client side scripts and are completely removed like comments are when a executable program is compiled.

It took me some time to notice this behaviour. One day when I did not have to smash other marketing automation problem I did some investigation, and lo and behold, it’s actually a common “feature”. With that in mind, I’ve found a simple workaround on YouTube. Let’s take a look at the content block (snippet of code)

%%=Concat('<','scr','ipt>')=%%
  //your client side javascript
  var 1plus1 = ()=>1+1
%%=Concat('</','scr','ipt>')=%%

On cloud page we simply reffer to this block by

%%=treatascontent(ContentBlockByKey('client_side_js'))=%%

Oh hi there 👋
I have a SSJS skill for you.

Sign up now to get an SSJS skill that can be used with your AI companion

We don’t spam! Read our privacy policy for more info.

Share With Others

The author
Marcel Szimonisz Platinum

Marcel Szimonisz

Marketing Automation Consultant

I specialize in solving marketing technology challenges, automating processes, and turning ideas into practical solutions with Salesforce Marketing Cloud and Adobe Campaign. Through MarTechNotes, I share technical guides and insights that make complex topics easier to understand

Latest badges
Weekend Regular Weekend Regular Profile Complete Profile Complete Simple Start Simple Start 5 Day Streak 5 Day Streak First Comment First Comment

Your email address will not be published. Required fields are marked *

Get exclusive tips, scripts and news

Choose your topics

We don’t spam! Read our privacy policy for more info.

Similar posts

Add to this article

Share your experience

Your contribution

Article history

What changed