title: How to make GTM Tags wait for some jQuery to be loaded?
body: <p>I would like to track if a toast (or any "popup element") gets displayed using Google Analytics Event Tracking via GTM.
  Whether or not the toast gets displayed is defined by jQuery code and based on cookie information like so</p>
  
  <pre><code>function ShowToast(Msg){
      $('#toast-msg').html(Msg);
      $('#toast').animate({ left: '-10px' });
  }
  </code></pre>
  
  <p>called by</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(function() {
          ShowToast("SOME HTML");
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>This is what I got in GTM so far using a <strong>custom variable</strong></p>
  
  <pre><code>function(){
      if(document.querySelector("#toast #toast-msg").length &gt; 0){
          return true;
      }
  }
  </code></pre>
  
  <p>with a trigger listening for this variable to be true and the usual Universal Analytics Event Tag. The idea is to simply check if the toast-msg is shown or not, which works fine in preview mode.</p>
  
  <p>Now to the problem: The tag is listening to gtm.js (pageview), but the jQuery code from the toast might load only after gtm.js is ready. Hence, sometimes the toast is not yet displayed when the tracking code is ready to fire and the event is not recorded.</p>
  
  <p><strong>Is there a way to use GTM and Javascript / JQuery to make sure all JQuery is loaded before GTM variables/triggers/tags are resolved? Or a completly different approach?</strong></p>