CrocoDillon / universal-react-redux-boilerplate

Step by step creation of a Universal React + Redux Boilerplate
Other
176 stars 33 forks source link

How to add external script #33

Closed newkolay closed 5 years ago

newkolay commented 7 years ago

Hello, first of all, great boilerplate. I could finally set server rendering with this code. The only problem i have is to add external scripts (google analytics, fb pixel, mixpanel, etc.) I've tried add it to Html.js but got error 'Unexpected token'. Any help please? Thank you

CrocoDillon commented 6 years ago

You probably either need to use dangerouslySetInnerHTML or add the script contents as a string (didn't test it though)... e.g.

<script>{`
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]\|\|function(){
  (i[r].q=i[r].q\|\|[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  
  ga('create', 'UA-XXXXXXXXX-X', 'example.com');
  ga('send', 'pageview');
`}</script>