I believe you could create a .js file in your public folder that contains the code inside the dangerouslySetInnerHTML block and add that as the src of the <script> tag.
So create a file in the public dir, e.g. /public/gtag-init.js, with the following contents:
<Head><scriptasyncsrc={`https://www.googletagmanager.com/gtag/js?id=${GA_MEASUREMENT_ID}`}/><scriptasyncsrc="/gtag-init.js"// or the name of the file you created/></Head>
Let me know how you get on and I will update the article, thanks!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Is there any other way to do this without using
dangerouslySetInnerHTML
?Hi, thanks for commentting!
I believe you could create a
.js
file in your public folder that contains the code inside thedangerouslySetInnerHTML
block and add that as thesrc
of the<script>
tag.So create a file in the
public
dir, e.g./public/gtag-init.js
, with the following contents:and then change the
<Head>
tag to be:Let me know how you get on and I will update the article, thanks!