Note that server-side code is executed before client-side code.
I came across a situation like this:
My internal code tracks every movement on the website, and the indicator for the visitor is a cookie. However, for the initial visit, when the user does not have a cookie, my function will save this movement with an undefined indicator, because the user's request is processed before the generation of cookies.
So, in this case, I would go with a cookie file.
In the meantime, I like to create client-side cookies when I need to fix a broken WordPress website, and I use the external Node.JS API as glue.
Kunok
source share