How to store a number (coming from cookie) into query vars for later usage in other filters?

The cookie is stored on the user’s computer. The page is generated on the server. Somehow, you must make sure the cookie is transported back to the server when the user clicks on a link to fetch a second page.

The instrument for this is javascript. You must send a script with the page that reads the cookie and adds the cookie content as a query_var to any internal link, so when it is clicked the query_var is sent to the server.

  1. Make the script to read the cookie. I trust you have already done
    this.

  2. In your theme, make sure all internal links have a class
    that you can use to trigger a script that will in turn trigger the
    cookie script and add the query_var to the url.

I realise this answer is incomplete in terms of code, but I hope you get the idea.