Track Logins via custom JS, etc

I've created a clunky way to track user logins:

  • create a Login object
  • add a date/time "last login" field on the user object
  • set Page Rules to redirect to the homepage if Last Login is blank or before today
  • set Page Rules on homepage to hide all views except a single "Get Started" form if Last Login is blank or before today
  • the Get Started form has no fields... only 2 record rules: 1) update record > Last Login > current time and 2) insert Login record with current time set in a date/time field. Submit Rule refreshes (redirects to the same page) and Page Rules reveal the previously hidden views.
  • After today, the user will need to click the Get Started submit form again... on and on.
  • This works, but it requires daily Get Started submissions and so it's not an ideal UX.

Has anyone had luck with accomplishing the above automatically upon submission of a login form, using custom JS or otherwise?

Hello Tanner - im trying to implement a similar thing but don't know JS really.

 

What I would like to track each time a user visits the homepage of our app.

 

I created a form on the home page that doesn't have any inputs but using record rules updates a date/time field that is on the user object called Last Login.

 

I hid the form with CSS

#view_1005 {
position: absolute !important;
left: -999999px !important;
}

 

And then im trying to use JS to update that field automatically on load.

The problem is that this auto submits ALL buttons on the page. I would like for it to only submit that views button but don't know how to target it.

$(document).on('knack-view-render.view_xxx', function(event, view) {
$('button[type=submit]').submit();
});

I know this is an older post, but to submit just the one form, use the function below, rather than a function that calls submit to all buttons of the submit type.

$(’#view_xxx>form’).submit();

I have written a post about setting up auditing in Knack apps - you can read here:

Hope this helps.

Julian