How to track and retrieve user login history in Memberstack 2.0 without custom development?

Post author
Jasper Huesgen

Hi there, is it possible to track user logins from the past months via Memberstack or any similar add-on app? Would much appreciate your help. Thank you!

Comments

11 comments

  • Comment author
    Memberstack Team
    • Official comment

    You can definitely use Script #193 – Member Activity Timeline Tracker for this. It’s designed to log member interactions like logins, signups, and plan changes into a timeline, so each login event gets recorded with a timestamp. That means you’ll be able to look back and see all of a user’s logins over the past months, not just the most recent one. It’s a straightforward way to build a history of activity that’s tied to each member profile.

    Script #193 is designed to log member interactions (like logins) into a timeline. Each login event gets recorded with a timestamp. From that data, you can:

    1. Count logins per day

      • Group timeline entries by date.

      • Count the number of login events for each day.

    2. Generate a chart

      • Use those daily counts to plot a line chart or bar chart showing login activity over time.

      • Example:

        • Dec 1 → 12 logins

        • Dec 2 → 8 logins

        • Dec 3 → 15 logins

    3. Display to admins or members

      • Admins can see overall activity trends.

      • Members can see their personal login history.

     

  • Comment author
    Alastair Budge

    If you integrate Profitwell then you can see this kind of activity through their dashboard. Not perfect (and I wish MS had it natively), but it is better than nothing.

    1
  • Comment author
    Sarwech Shar

    Hey Jasper! Do you want a chart of the number of logins per day or do you need to know anything else?

    In case it's useful, you could try Nocodelytics, an analytics tool for Webflow which supports Memberstack (disclaimer: I'm a co-founder). You can set up the tracking so it shows how many people complete the login form each day or visit a specific page (like their dashboard). 

    3
  • Comment author
    Maxime Dubé

    Hi, is there any way to track member logins in Memberstack 2.0? I want to know how many times a user logs into their account.

    Google Analytics is usually for general metrics; what I need is to know this metric for each individual member
    I was able to do that in Memberstack 1.0
     
    I had just copied and pasted a little code on Webflow, and it worked.
    But I don’t remember where I found this and how I made that work
    I’m not sure if this also work with 2.0
    0
  • Comment author
    Raquel Lopez

    Analytics is for everything about metrics. You can have an overall overview of all your users behaviors in one place. And you can track logins and pageviews and other metrics per user if you send the user id in the metric.

    internally Memberstack has an event log where you can track the events per user to debug any situation. You can open the panel in the options of the user or go to the events panel or in the event panel

    If you want to save each login data per user as you are showing in your comment, you can just create a snippet code that per each login attempt would save it in the member json of the user. You won't be able to compare analytics, it would be the same as looking as the event log 🤔 You can ask https://rey.memberstack.com/ MS ai to help you out with the script or to transform your v1 script to v2.

    0
  • Comment author
    Maxime Dubé
    <!-- Memberstack - History member tracking start -->
    <script type="text/javascript">
      MemberStack.onReady.then(async function(member) {
        // Check if the member is logged in
        if (member.loggedIn) {
          // Get the metadata object
          const metadata = await member.getMetaData();
          
          // Use Date.now() to get the current timestamp
          const timestamp = new Date(Date.now()).toString();
          
          // Initialize userVisits if it doesn't exist
          metadata.userVisits = metadata.userVisits || [];
          
          // When the page loads, track the visit
          window.onload = async function() {
            // Check if the timestamp already exists in userVisits
            if (metadata.userVisits.indexOf(timestamp) === -1) {
              // Push the timestamp to the userVisits array
              metadata.userVisits.push(timestamp);
              
              // Update the visit count
              const visitCount = metadata.userVisits.length || 0;
              metadata.WelcomeVisitsNumb = visitCount;
              
              // Update Memberstack with the new metadata object
              await member.updateMetaData(metadata);
              
              // Update the visits count display
              document.querySelector('.visits-count').textContent = visitCount;
            }
          };
          
          // Display the current visit count
          if (metadata.WelcomeVisitsNumb) {
            document.querySelector('.visits-count').textContent = metadata.WelcomeVisitsNumb;
          } else {
            document.querySelector('.visits-count').textContent = 0;
          }
        }
      });
    </script>
    <!-- Memberstack - History member tracking end -->
    

    I asked Memberstack AI to translate my code from 1.0 to work with 2.0
    I added this code inside Before

    and then added this:
    { 
    "userVisits": [],
    "WelcomeVisitsNumb": 0
    }
    here is memberstack 2.0
    it doesn’t seem to count anything tho… not sure what doesn’t work
    0
  • Comment author
    Raquel Lopez

    Try this

    <!-- Memberstack - History member tracking start -->
    const memberstack = window.$memberstackDom
    
    if (window.$memberstackReady) {
        // Run the code immediately if Memberstack is already ready
        init();
    } else {
        // Wait for Memberstack to be ready if it's not already
        document.addEventListener("memberstack.ready", init);
    }
    
    async function init() {
        // Check if the member is logged in
        const currentUser = JSON.parse(localStorage.getItem("_ms-mem"));
    
        if (currentUser) {
            // Get the metadata object
            const metadata = await memberstack.getMemberJSON();
    
            // Use Date.now() to get the current timestamp
            const timestamp = new Date(Date.now()).toString();
    
            // Initialize userVisits if it doesn't exist
            metadata.userVisits = metadata.userVisits || [];
    
            // When the page loads, track the visit
            window.onload = async function () {
                // Check if the timestamp already exists in userVisits
                if (metadata.userVisits.indexOf(timestamp) === -1) {
                    // Push the timestamp to the userVisits array
                    metadata.userVisits.push(timestamp);
    
                    // Update the visit count
                    const visitCount = metadata.userVisits.length || 0;
                    metadata.WelcomeVisitsNumb = visitCount;
    
                    // Update Memberstack with the new metadata object
                    await memberstack.updateMemberJSON({json: metadata});
    
                    // Update the visits count display
                    document.querySelector('.visits-count').textContent = visitCount;
                }
            };
    
            // Display the current visit count
            if (metadata.WelcomeVisitsNumb) {
                document.querySelector('.visits-count').textContent = metadata.WelcomeVisitsNumb;
            } else {
                document.querySelector('.visits-count').textContent = 0;
            }
        }
    }
    
    0
  • Comment author
    Maxime Dubé

    It almost work perfectly!

    Instead of updating “WelcomeVisitsNumb” it add another line

    This is what happen after 3 visits

    0
  • Comment author
    Raquel Lopez

    Uhm, use this declaration. It think it should fix it 🤔

    // Get the metadata object
    const metadata = (await memberstack.getMemberJSON()).data;

    Look for the comment that says // Get the metadata object and replace the declaration.

    const memberstack = window.$memberstackDom; 

    if (window.$memberstackReady) {
    // Run the code immediately if Memberstack is already ready
    init();
    } else {
    // Wait for Memberstack to be ready if it's not already
    document.addEventListener("memberstack.ready", init);
    }

    async function init() {
    // Check if the member is logged in
    const currentUser = JSON.parse(localStorage.getItem("_ms-mem"));

    if (currentUser) {
    // Get the metadata object
    const memberJson = await memberstack.getMemberJSON();
    const metadata = memberJson.data || {};

    // Use Date.now() to get the current timestamp
    const timestamp = new Date(Date.now()).toString();

    // Initialize userVisits if it doesn't exist
    metadata.userVisits = metadata.userVisits || [];

    // When the page loads, track the visit
    window.onload = async function () {
    // Check if the timestamp already exists in userVisits
    if (metadata.userVisits.indexOf(timestamp) === -1) {
    // Push the timestamp to the userVisits array
    metadata.userVisits.push(timestamp);

    // Update the visit count
    metadata.WelcomeVisitsNumb = metadata.userVisits.length || 0;

    // Update Memberstack with the new metadata object
    await memberstack.updateMemberJSON({ json: { data: { ...metadata }
    } });
    }
    };
    }
    }
    0
  • Comment author
    Maxime Dubé

    It is collecting data but the same problem occur. Each visit appears to be creating a new JSON structure, instead of appending to an existing one.

    I found the solution with Memberstack AI I think

    it works!
    <!-- Memberstack - History member tracking start --> 
    <script type="text/javascript">
    const memberstack = window.$memberstackDom;

    if (window.$memberstackReady) {
    // Run the code immediately if Memberstack is already ready
    init();
    } else {
    // Wait for Memberstack to be ready if it's not already
    document.addEventListener("memberstack.ready", init);
    }

    async function init() {
    // Check if the member is logged in
    const currentUser = JSON.parse(localStorage.getItem("_ms-mem"));

    if (currentUser) {
    // Get the metadata object
    const memberJson = await memberstack.getMemberJSON();
    const metadata = memberJson.data || {};

    // Use Date.now() to get the current timestamp
    const timestamp = new Date(Date.now()).toString();

    // Initialize userVisits if it doesn't exist
    metadata.userVisits = metadata.userVisits || [];

    // When the page loads, track the visit
    window.onload = async function () {
    // Check if the timestamp already exists in userVisits
    if (metadata.userVisits.indexOf(timestamp) === -1) {
    // Push the timestamp to the userVisits array
    metadata.userVisits.push(timestamp);

    // Update the visit count
    metadata.WelcomeVisitsNumb = metadata.userVisits.length;

    // Update Memberstack with the new metadata object
    await memberstack.updateMemberJSON({ json: metadata });
    }
    };
    }
    }
    </script>
    <!-- Memberstack - History member tracking end -->
    Everything seems to work just fine with this code
     
    Thank you very much for helping me Raquel!
    0
  • Comment author
    Philipp Schwarz
    • Edited

    Maxime Dubé Raquel Lopez

    This is awesome! I've been looking for this for a while. Thank you!!!

    1

Please sign in to leave a comment.