Home > Software design >  Is there a way to track button click by Button ID using Komito analytics
Is there a way to track button click by Button ID using Komito analytics

Time:07-28

I am using Komito Analytics to track Events in Google Analytics. So far they are doing good. I would like to create 2 different buttons with different ids or classes and track them separately. is that possible?

CodePudding user response:

Depending on your needs and current implementation, you can use one of the following methods:

  1. Enable trackForms to track forms submissions and wrap each button in a <form> element:
<form onsubmit="return false">
  <button type="submit" name="action1">Button 1</button>
<form>
<form onsubmit="return false">
  <button type="submit" name="action2">Button 2</button>
<form>
  1. Enable trackActions to track CTA actions for links and use links instead of buttons:
<a href="javascript:void('action1')">Links 1</a>
<a href="javascript:void('action2')">Links 2</a>
or
<a href="javascript:'action1';void 0">Links 1</a>
<a href="javascript:'action2';void 0">Links 2</a>

CodePudding user response:

You can count the number of clicks on the button with Javascript

<button id="komito">komito</button>


<script type="text/javascript">
        var count = 0;
        var btn = document.getElementById("komito");
  
        komito.onclick = function () {
            count  ;
console.log(count);
        }
    </script>
  • Related