When you add the async
parameter to the Roistat script, it stops working.
Our theory is that the async loading issue is caused by the fact that the roistat_visit
cookie isn't yet set when async loading a script, so the script always tries to load the init file instead of the main module.
DISCLAIMER:
The script was developed blindly and has not been tested in production.
Script feedback has not yet been provided by the person who requested help.
In order to potentially solve this problem, our script:
- Prevents the original script from loading.
- Loads components sequentially: first the main
module.js
, then the init script if necessary. By doing so, the correct initialization sequence is ensured. - Checks if
w.roistat
object is defined after loadingmodule.js
. If it is not, loads the init script. The problem of missing cookies on the first visit is now resolved. - Runs asynchronously (
js.async = 1
), which does not block the page loading while maintaining full control over its execution. - Handles errors and retries.
- Implements timeouts.
- Eliminates duplication.
- Logs informatively.
Add this script to your pages template before calling Roistat's original script.
Have any questions? Create a new issue, I will try to help you.