URL Parameters

Why is there not a better resource for this? The things I would like to do are as follows. Ideally, this can be done by adding some simple lines of code to the site code tab, without having to add any code page-by-page.

What I need:
IF a url contains a parameter such as /page?ID=42

Then

  1. Save the parameter value to cookies

  2. If user clicks any other buttons or page links on the site, carryover or load the same parameter to the url on the new page (basically just keep the params in the url as a user navigates around our site)

  3. If user leaves and returns within a defined period, reload the parameters from cookies and append to url for same behavior as above

  4. Then be able to pass parameters into a jotform i-frame embed and/or wix contact form.

The easiest way to do this would be to use the wix-storage API to save the values - either by session or “permanently”. This would avoid the complication of having to keep track of the URL query parameters.

I guess my point is that the documentation around HOW to do this is extremely lacking. Please, using the wix-storate API, show me EXACTLY what code to use on the site to:

  1. Get all of the parameters from the URL

  2. Save them to wix-storage

  3. Retrieve them on another page later on for use in a form or i-frame.

@david6761
Get query pramas:
https://www.wix.com/corvid/reference/wix-location/query

Store prams in cache:
(use JSON.stringify() if you want to use the full object)
https://www.wix.com/corvid/reference/wix-storage/session
https://www.wix.com/corvid/reference/wix-storage/storage/setitem

Retrieve from the cache:
(use JSON.parse if you saved the full object):
https://www.wix.com/corvid/reference/wix-storage/storage/getitem

@jonatandor35 Total newb here. Trying to piece this together is a real challenge for me. How close am I with the below?

import {session} from ‘wix-storage’ ;
import wixLocation from ‘wix-location’ ;
// …
let query = wixLocation.query;

session.setItem(console.log(JSON.stringify({ x: 1 , y: 2 })));

let value = session.getItem( const obj = JSON.parse(json));

wixLocation.queryParams.add({ const obj});

@david6761

import {session} from 'wix-storage';
import wixLocation from 'wix-location';
// ...
let query = wixLocation.query; 
if(query){
    session.setItem("query", JSON.stringify(query));
} else {
    let value = session.getItem("query");
    if(value){
        wixLocation.queryParams.add(JSON.parse(value));
    }    
}