nfl / react-helmet

A document head manager for React
MIT License
17.34k stars 660 forks source link

Insert script tags in the <head> from CMS #673

Closed dongepulango closed 2 years ago

dongepulango commented 2 years ago

My team is working on a Gatsby project with a Wordpress headless CMS. We want our users to add their custom scripts in the <head> for like tracking and other stuff. We want them to add multiple script tags.

Our current solution is to have like a textarea in the CMS where client can enter some <script> with src or with actual script on them.

example:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-149917166-4"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-149917166-4');
</script>

so we query that data and tried to insert in the <head> using react-helmet and the scripts with src worked, but the script with javascript inside gets ignore. Is this the wrong approach? thanks in advance