Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save getmanzooronline/4fb5e5624e10da8c54bbabe69551381e to your computer and use it in GitHub Desktop.
Save getmanzooronline/4fb5e5624e10da8c54bbabe69551381e to your computer and use it in GitHub Desktop.
function readUTMParams() {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const utmParams = {};
const utmPrefix = "utm_";
for (const param of urlParams.entries()) {
if (param[0].startsWith(utmPrefix)) {
utmParams[param[0]] = param[1];
}
}
return utmParams;
}
// Read utm params
const utmParams = readUTMParams();
console.log(utmParams);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment