I would like to track a login event on my website. The user writes username and pass then clicks on login, the form is submited and server checks if password is correct then redirect to the home page if it is. But how could I add a Login event to GA? If I add it to the login button it wont be totally accurate as it will count even the failed login attempts.
Any ideas on how to solve this?
Thanks Chris
Enable the Google Analytics User ID tracking feature by expanding the "Tracking info" property and then clicking on "User-ID". On the next page you can enable the feature and create a User-ID view. This view will show only data from registered users.
Great question!
I think what you want is the Custom Variables that google analytics offers.
Simply put, for each page your user visits you set a custom variable with it's username for example.
I don't think you are interested in the login event, rather you are interested in what a logged in user visits - and this solution solves your problem
The Custom Variables answer will serve your purposes as outlined below but if you want another alternative (or actually really want to use Track Events) you could also add in a parameter to a successful logon which you can then read and process as you wish.
So for example:
<a href="<?php echo wp_login_url(get_permalink().'?login=true'); ?>">Login</a>
This will create a link to your login page. If the login is successful it will redirect back to the current page with the parameter login=true in the URL.
(You could check this parameter via JS for example and fire the Analytics track event call based on this).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With