title: How is Google analytics gtag supposed to work in a SPA?
body: <p>From what I can tell, how google recommends to set up gtag, it's a function that is always pushing more variables onto an array: </p>
  
  <pre><code>window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  </code></pre>
  
  <p>Following the docs on how to use it in a SPA, it seems I'm actually creating a memory leak.</p>
  
  <pre><code>gtag('config', 'GA_TRACKING_ID', {'page_path': '/new-page.html'});
  console.log('window.dataLayer', window.dataLayer);
  </code></pre>
  
  <p>My console shows that every time I navigate to a new page the window.dataLayer array gets larger. </p>
  
  <p>I'm assuming there's something I'm not understanding, because I doubt that Google wants me to create a memory leak in my app, but I'm stumped now. </p>