5

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 ?

sunshine
  • 125
  • 4
  • 15

2 Answers2

4

You can use the events tracking API:

<a onclick="javascript:_paq.push(['trackEvent', 'User', 'Login']);">Log In</a>
Lukas
  • 9,765
  • 2
  • 37
  • 45
  • 3
    Is part of the problem that this event is queued but the queue is never flushed because of the page reload implicit in clicking on a link? – Jason Sperske Oct 07 '14 at 22:56
2

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>
NickStees
  • 449
  • 4
  • 12