Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Piwik : Track event on a button click which redirects to a web page

Tags:

matomo

I have integrated Piwik in my web site, where I want to track successful and unsuccessful logins. The successful login will redirect the user to Home page, where as on unsuccessful it will redirect to Login Page. Now, If I am trying to send request to Piwik, but mean while it redirects the page to Home /Login.

Can anyone tell me, how I can handle this situation ?

like image 880
sunshine Avatar asked Jul 24 '14 13:07

sunshine


2 Answers

You can use the events tracking API:

<a onclick="javascript:_paq.push(['trackEvent', 'User', 'Login']);">Log In</a>
like image 105
Lukas Avatar answered Oct 23 '22 16:10

Lukas


If you are using jQuery you could alternately do something like this. Even though the user is clicking a link and leaving the page it should still record the event since the requests are sent in parallel.

<body>
  <div class="menu">
    <ul>
      <li><a href="/login">Login</a></li>
    </ul>
  </div>
</body>
<script>
$(function() {
  $('.menu li > a').click(function() {
    _paq.push([ 'trackEvent', 'Menu', 'Click', $(this).text() ]);
  });
});
</script>
like image 38
NickStees Avatar answered Oct 23 '22 17:10

NickStees