🔥 500+ people already subscribed. Why not you? Get our newsletter with handy code snippets, tips, and marketing automation insights.

background shape
background shape

Use client-side JavaScript in content block

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

Marcel Szimonisz

MarTech consultant

I specialize in solving problems, automating processes, and driving innovation through major marketing automation platforms—particularly Salesforce Marketing Cloud and Adobe Campaign.

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

Similar posts