Simple Event Firing

by Alex Cowan

HTML

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-130183387-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];

  function gtag() {
    dataLayer.push(arguments);
  }
  gtag('js', new Date());

  gtag('config', 'UA-130183387-2');

</script>

<button id='search-btn' onClick='doga("thecat", "theact", "thelabel", 1)'>
click me
</button>

JavaScript

function doga(category, action, label, value) {
  console.log('did GA');
  console.log(category, action, label, value);
  gtag('event', 'click', {
    'event_category': 'Suttons',
    'event_action': 'Doooj', 
    'event_label': 'shlabel', 
    'event_value': '1'
  });
}