title: Google Analytics ga function hitCallback is not firing
body: <p>I'm trying to trigger an event in Google analytics for a client. The event needs to be triggered when the user clicks on a link to another website. The function call that was placed in onclick was not working on desktop because the page was getting unloaded before the Javascript could run. In order to fix it, I implemented the following code based on <a href="https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits#knowing_when_the_hit_has_been_sent" rel="nofollow noreferrer">this article</a>:</p>
  <pre><code>&lt;script&gt;
    function submitOrderButtion( eventName ){
      var url = 'https://example.com';
      var goToOrderForm = function(){
        console.log( &quot;goToOrderForm&quot; );
        window.location = url;
      };
      //setTimeout( goToOrderForm, 1000 );
      console.log( ga.q );
      console.log( ga.loaded );
      ga('set', 'transport', 'beacon');
      ga('send', 'event', 'order online', 'click', eventName, {
        hitCallback: goToOrderForm
      });
    }
  &lt;/script&gt;
  </code></pre>
  <p>The link that calls the function is this:</p>
  <pre><code>&lt;a href=&quot;javascript:&quot; onclick=&quot;submitOrderButtion( 'homepage' );&quot; class=&quot;btn btn-primary&quot;&gt;Order Online!&lt;/a&gt;
  </code></pre>
  <p>The ga function never does anything when the button is clicked.</p>
  <p>ga.q is undefined, and ga.loaded is true. I set the transport to 'beacon' for the last try, but it made no difference. Unless I uncomment the setTimeout (which I eventually will when this is working) the callback is never called, the ga event is never logged, and no network requests ever show up in the inspector.</p>
  <p>Here is a link to the site <a href="https://joeysnycpizza.com/" rel="nofollow noreferrer">Joey's Pizza</a>. The link in question is the big button in the middle of the page that says &quot;ORDER ONLINE!&quot;.</p>
  <p>Can anyone tell me why the ga function is not doing anything? Thanks in advance for your help!</p>
  <p><strong>Status Update:</strong>
  I'm still looking for an answer to this. The answer I got has been tried multiple times (with various arg configurations, and checking the source to make sure previous tries were not cached). I've spent almost a days worth of work on what should be a simple task, and I'm not getting any errors or anything. Any further help would be very appreciated! Thank you :)</p>