experiment with encoding URI params

by Richard Hunter

JavaScript

const foo = "http://www.foo.com"

function updateURL(oldURL, { refdomain, utm }) {
	const url = new URL(oldURL);

	url.searchParams.append('hearst_refdomain', refdomain);
	url.searchParams.append('hearst_utm', utm);

	return url.href;
}

const utm = {
	foo: 'this is f?][oo',
}

const urlParams = {
	refdomain: 'sfsf',
  utm: JSON.stringify(utm),
}

const updatedURL = updateURL(foo, urlParams);

// on receipt of URL
const url = new URL(updatedURL);

for (const [key, value] of url.searchParams) {
	console.log('key:', key, 'value:', value)
}