schnitzel frito
schnitzel frito

Reputation: 19

How to check if a user has navigated away from a Power Apps screen?

I'm developing a quiz app in Power Apps and need a way to track whether a user has navigated away from a specific screen or opened another application/tab. The idea is to prevent users from accessing another tab to see the answers.

Is there a method to detect user inactivity or navigation events within Power Apps? I'm looking for strategies to manage user sessions and ensure they remain engaged with the app. Any suggestions or best practices would be greatly appreciated!

I tried using the OnVisible and OnHidden properties to manage user activity, expecting them to help detect when users navigate away from the quiz screen. However, they don't provide the tracking I need for external navigation.

Upvotes: 0

Views: 156

Answers (1)

Laviza Falak Naz
Laviza Falak Naz

Reputation: 446

you need to Address this by binding a Document Visibility Tracker. Here's a sample function and you can add more actions like popup, warning or ending something as per your requirement.

enter image description here

To Bind it, add the JS to your form and bind it to OnLoad and OnSave Events like this

enter image description here

Function:

var ActivityTracking = {
init: function() {
    console.log("Initializing Activity Tracking with visibilitychange");

    document.addEventListener("visibilitychange", function() {
        if (document.hidden) {
            ActivityTracking.userLeftTab();
        } else {
            ActivityTracking.userReturnedToTab();
        }
    });
},

userLeftTab: function() {
    console.log("User has navigated away from the tab.");
    // Add any additional behavior you want here, like tracking or alerts
},

userReturnedToTab: function() {
    console.log("User has returned to the tab.");
    // Add any additional behavior you want here, like tracking or alerts
    }
};
ActivityTracking.init();

Upvotes: 0

Related Questions