title: Add google analytics gtag code snippet in React
body: <p>I have the following Google Analytics (gtag) code to be added in my React project.
  I am trying to add it in render() method. But its not working. How to resolve it. Thanks.</p>
  
  <pre><code>&lt;script async src="https://www.googletagmanager.com/gtag/js?id=#######"&gt;&lt;/script&gt;
  &lt;script&gt;
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', '#########');
  &lt;/script&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/BIfST.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BIfST.png" alt="enter image description here"></a></p>