title: Google Tag Manager - Create Event with Inline onclick attribute
body: <p>I have a website where I am using Google Tag Manager to fire my Google Analytics tracking.</p>
  
  <pre><code>&lt;!-- Google Tag Manager --&gt;
  &lt;script&gt;
  (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  j=d.createElement(s),dl=l!='dataLayer'?'&amp;l='+l:'';j.async=true;j.src=
  'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  })(window,document,'script','dataLayer','********');
  &lt;/script&gt;
  &lt;!-- End Google Tag Manager --&gt;
  </code></pre>
  
  <p>On the page, I wanted to track link clicks that open a modal window.</p>
  
  <p>So, I put this code:</p>
  
  <pre><code>onclick="ga('send', 'event', 'Test', 'Take-Test', 'English');"
  </code></pre>
  
  <p>However, that is not working and it's not pushing the event into Analytics.</p>
  
  <p>After doing a lot of digging, I thought maybe the issue is that GTM uses gtag.js instead of the older analytics.js library, so the structure of my onclick event had to be different.</p>
  
  <p>My source for this was: <a href="https://developers.google.com/analytics/devguides/collection/gtagjs/migration#track_events" rel="nofollow noreferrer">https://developers.google.com/analytics/devguides/collection/gtagjs/migration#track_events</a></p>
  
  <p>Based on this, I'm thinking my onclick event has to look like this:</p>
  
  <pre><code>onclick="gtag('event', 'Take-Test', {'event_category': 'test','event_label': 'English'});
  </code></pre>
  
  <p>However, I can't seem to confirm that with a GTM implementation it is using gtag.js, so I don't know if this is correct still.</p>
  
  <p>All I know is that I really want to push this event into Analytics properly.</p>
  
  <p>As a side note, I realize I can probably create GTM firing rules for this, however for reasons beyond my control, I have to create the onclick event in the HTML code and not via GTM.</p>
  
  <p>Many thanks in advance for any insight!</p>