How to Embed JS into the <HEAD> using a CMS Collection

Hey all,

Is it possible to embed javascript code into the of the page using a CMS Collection to dynamically add it in?

I’ve tried the following methods from this forum and none are working:

  1. Added the full script including the .

  2. Added an embed field onto the page and pulled Tracking Code A into the embed field.

  3. Added a rich text CMS Collection item called “Tracking Code C”. Added a Rich Text field onto the page and pulled the content from the CMS collection.

In ALL options, Webflow encoded the value of the embeds.

Here was my original code:

<script>prefinery=window.prefinery||function(){(window.prefinery.q=window.prefinery.q||[]).push(arguments)};</script>
<script src="https://widget.prefinery.com/widget/v2/cdmokyya.js" defer></script>

Here is what happens to the code after publishing:
&lt;script&gt;prefinery=window.prefinery||function(){(window.prefinery.q=window.prefinery.q||[]).push(arguments)};&lt;/script&gt;&lt;script src=&quot;https://widget.prefinery.com/widget/v2/cdmokyya.js&quot; defer&gt;&lt;/script&gt;

Here is a video showing all steps taken:
https://www.loom.com/share/400641e3b96a46b89e40a8ccfb296679

What can I do? Thank you so much in advance for your help!

P.S. Here is my URL I’m testing it on.

Hi @DavidDL,

You could try this method to see if it works for you:

Add a Rich Text field to your CMS Collection, press the + button inside the field and paste the code.

On the CMS Template page, add a Rich Text Block then connect it to the Code field. This isn’t in the head tags but it avoids the encoding.

Here’s a video demo: Screen Recording 2022-05-14...

Would love to hear if there’s a better way to do this.