4

I had register my website in the google analytics and I had put the script in my default index like this :

<html>

<head>

    <meta name="google-site-verification" content="****************" />

    <script async src="https://www.googletagmanager.com/gtag/js?id=AW-7**4*7***"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'AW-7**4*7***');
</script>
</head>

<body>
...
<a class="" href="/Contents/Make-App">
    <div class="text">Make app</div>
</a>
...
<script src="/Content/assets/script/combined.min.js" type="text/javascript"></script>

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-*4**0**6-*"></script>

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-*4**0**6-*');
</script>
</body>

</html>

I want if I click button "make app", it will be listed on Google Analytics. so I can see how many people clicked on that button

How can I do it?

1
  • @closetnoc What the solution? – Success Man Sep 25 '19 at 4:18
4

You are using gtag.js tracking code. Syntax for event tracking for gtag.js is:

gtag('event', 'action', {'event_category': 'category', 'event_label': 'label', 'value': value});

If it does not require a value, the parameter can be omitted.
Add it to your button using onclick eg

<button onclick="gtag('event', 'click', {'event_category': 'button', 'event_label': 'make app'});">Make App</button>

Ref: https://developers.google.com/analytics/devguides/collection/gtagjs/events

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.