I found a solution for the problem.
- Create an empty SQL query
- Make sure the query is set to "Automatic"
- Create a JS query which has the functionality you need on page load
- Set the JS query in the event handler:
I made the scriptOnPageLoad global so it can be run on every page. The SQL query needs to be on each page, except your landing page, or you will run in a endless circle