title: Push to dataLayer on initial app load Reactjs
body: <p>I have an app which has GTM tracking. I'm currently checking when a route has taken place and pushing a page_view event to the dataLayer. </p>
  
  <p>The problem I'm having is getting the dataLayer to push when the app loads initially. I have a back button which when clicked goes back to the home screen and fires an event but I can't get it to fire when the app loads initially. I can explicitly add the push event to the home component when it mounts, which will work but when I click the go back button it will fire twice. </p>
  
  <p>Here's my code does anyone know how to get this to work when the app loads initially without duplicating the push?</p>
  
  <pre><code>componentDidUpdate(prevProps) {
      if (this.props.path !== prevProps.path) 
      {
          this.routeChange();
      }
  }
  routeChange(){
     window.dataLayer.push({
          event: "page_view",
          url: this.props.path
      });
  }
  </code></pre>