title: How to use Google Tag Manager with history changes?
body: <p>I am trying to delpoy Google Tag Manage for Facebook Pixel on a website that is using "React" and "React Router"  that is not mine and I don't have access to source.</p>
  
  <p>I am using "History Change" trigger and checks for certain url changes. Then whenever user visits that page I get some data using queryselectors and send pixel event.</p>
  
  <p>The issue is the tag gets fired very early when the old page is still loaded and javacript queryselector returns data from the previous page , this goes on with all subsequent link clicks.</p>
  
  <p>Here is the code that I am using:'</p>
  
  <pre><code>  &lt;script&gt;
          var prodIdElement = 
      document.querySelector("span[itemprop=productId]");
          var product_id = prodIdElement.textContent;
          console.log(product_id);
          fbq('track', 'ViewContent', {
              content_type: 'product',
              content_ids: [product_id]
          });
    &lt;/script&gt;
  </code></pre>