Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track a login event in Google Analytics

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

like image 726
Chris Hki Avatar asked Dec 22 '11 13:12

Chris Hki


People also ask

How do I track a user logged into Google Analytics?

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.


2 Answers

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

like image 151
Tudor Constantin Avatar answered Nov 09 '22 05:11

Tudor Constantin


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).

like image 21
joesk Avatar answered Nov 09 '22 06:11

joesk