Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show live user count on website with Google Analytics

How can I show the number of visitors online at any page load via Google analytics?

E.g., when a visitor loads the page somewhere it will say "58 Visitors Online".

like image 336
Nicekiwi Avatar asked Aug 07 '11 22:08

Nicekiwi


People also ask

Can Google Analytics track logged in users?

While many marketers believe it's out of the question to track individual users in Google Analytics, it's not impossible. If your application or website has a login authentication system, then it is possible to track users in Google Analytics with it's User ID tracking feature.


1 Answers

This cannot be done in analytics; however, you can do this yourself by having a ping-back function in JavaScript, where every N seconds, you kick-off a "heart-beat" request to your server, using XHR, and include some sort of unique ID. When some amount of time (more than N seconds) passes without a heart-beat from a given ID, you can assume that the user is no longer actively on that site. Moreover, you can combine this with the visibility APIs to show only the set of users who are actively viewing the page (as opposed to users who have the page open but in a background tab).

like image 165
Michael Aaron Safyan Avatar answered Oct 12 '22 09:10

Michael Aaron Safyan