title: insert google analytics code in javascript file
body: <p>Maybe this Duplicate : <a href="https://stackoverflow.com/questions/3689518/google-analytics-in-js-file-instead">google analytics in JS file instead?</a></p>
  
  <p>I tried to add the code of Google's statistics to JS file And I could not do it.</p>
  
  <p>I tried 3 ways</p>
  
  <p>1.</p>
  
  <pre><code>document.getElementsByTagName('body')[0].innerHTML += "&lt;script&gt;(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-48139516-1', 'accessbar.co.il');ga('send', 'pageview');&lt;/script&gt;";
  </code></pre>
  
  <p>2.
  Insert the code to function and call the function on "window.onload".</p>
  
  <pre><code>function googleAna() {
  (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-48139516-1', 'accessbar.co.il');
  ga('send', 'pageview');
  }
  </code></pre>
  
  <ol start="3">
  <li>Enter the code as is to the JS file And let it load while reading the JS file</li>
  </ol>
  
  <p>In all cases, Google did not recognize I put the code.</p>