ThreeWP Activity Monitor
Tracking when logged in users visit the site? (6 posts)

  1. peripatew
    Posted 2 years ago #

    I'm experimenting with some online educational content for students, and need a way to "track attendance". I don't want them to have to login/logout for each visit. Is there a way to track their visits when they are already logged in?


  2. Richard van Denderen
    Posted 2 years ago #

    +1, I have almost the same question, for an online workshop I want to know what pages are viewed by specific users.

  3. blepharisma
    Posted 2 years ago #

    +1. We need Instructors to be able to track student visits, but not see the stats for every site on the network. I found that enabling the option to allow 'Administrators' to see others' logins gave them access to all of the stats for all of the sites. This goes against our privacy practices, so we can't enable it...

    I also agree that logins aren't as useful a stat as visits are. An already logged in user doesn't seem to add any stats when they visit a new site on the network.

  4. Frankie Jarrett
    Posted 1 year ago #

    I recently co-authored a plugin called Stream to track what logged-in users are doing.

    Would love to know what you think, and how it could be better!

  5. davidlieb
    Posted 1 year ago #

    Hi! Has anyone found a good solution for this? I am in almost exactly the same boat!

  6. Richard van Denderen
    Posted 1 year ago #

    I used a piece of code to generate a .csv file for every user and that contains the url, date/timestamp and the name.

    I included the following code(file) in the header of the site with

    if ( is_user_logged_in() ) {
        //do include code

    made a folder called 'logs' in the root of the site and protected that.

    global $current_user;
    $firstname = $current_user->user_firstname;
    $lastname = $current_user->user_lastname;
    $useremail = $current_user->user_email;
    $id = $current_user->ID;
    $permalink = $_SERVER['REQUEST_URI'];
    $date = date('Y-m-d H:i:s');
    function getDomainFromEmail($email)
    // Get the data after the @ sign
    $domain = substr(strrchr($email, "@"), 1);
    return $domain;
    // Example
    $domain = getDomainFromEmail($useremail);
    $data = "" . $id . ";" . $firstname . " " . $lastname . ";" . $permalink . ";" . $date . "\n";
    $file_name = "logs/".$firstname."-".$lastname."-".$id."-@".$domain.".csv";
    $max_lines = 250;              #maximum number of lines you want the file to have
    $new_line = $data;               #content of the new line to add to the file
    $file_lines = file($file_name);     #read the file's lines into an array
    #remove elements (lines) from the end of the
    #array until there's one less than $max_lines
    while(count($file_lines) >= $max_lines) {
        #remove the last line from the array
    #add the new line to the front of the array
    array_unshift($file_lines, $new_line);
    #write the lines to the file
    $fp = fopen($file_name, 'w');           #'w' to overwrite the file
    fwrite($fp, implode('', $file_lines));

    It isn't the most efficient way and I dont know how the web server is going to act when u have a lot of logged in users at the same time, but it works for me

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • ThreeWP Activity Monitor
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic