title: How to programatically send an event to GA4 without Google Tag Manager?
body: <p>I would like to send a custom event to the new Google Analytics programatically, without defining it in the GTM first.</p>
  <p>I am using Google Tag Manager and according to this article:
  <a href="https://developers.google.com/analytics/devguides/collection/ga4/translate-events" rel="nofollow noreferrer">https://developers.google.com/analytics/devguides/collection/ga4/translate-events</a></p>
  <p>It is only possible by defining an event in the GTM itself. I can not do that and would like to keep doing this using the old method, where you could just do:</p>
  <pre class="lang-js prettyprint-override"><code>        if (&quot;ga&quot; in window) {
              var tracker = ga.getAll()[0];
              if (tracker) {
                  tracker.send(&quot;event&quot;, eventCategory, eventAction);
              }
          }
  </code></pre>
  <p>How can I achieve this effect using JavaScript with the new Google Analytics (GA4)?</p>
  <p><code>window.gtag</code> is undefined as I'm using GTM, and <code>window.ga</code> is undefined as I'm using GA4. The only tag configured in the GTM is &quot;Google Analytics: GA4 Configuration&quot;.</p>