0

I have this type of URL:

www.domain.com/postname?emailid=somethingsomething

I must place this part:

somethingsomething

inside WP header, more accurate inside JS snippet, as follows:

<script>
window.HashedEmail = 'somethingsomething';
</script>

EDIT: Suggested answer shows how to extract particular data but not how to place extracted data into header, for example - how to manipulate with extracted dataset

TriviaFem
  • 13
  • 1
  • 5
  • Does this answer your question? [How can I get query string values in JavaScript?](https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – Konrad May 10 '22 at 18:50
  • Just partialy, because it shows how to extract particular data but not how to place extracted data into header, for example - how to manipulate with extracted dataset. – TriviaFem May 10 '22 at 19:16
  • I thought that you just want to assign query param to the `HashedEmail` variable. Is it right? Or do you have some header in html and you want to change it's value? – Konrad May 10 '22 at 19:24
  • Maybe I did not explain well or maybe I do not understand well, sorry. I need to have specific query string extraced from URL and that string placed exactly into script I mentioned above, inside WP header. – TriviaFem May 10 '22 at 20:06

1 Answers1

0

Maybe I missed something but this looks like a solution for me

const urlSearchParams = new URLSearchParams(window.location.search);
const emailid = urlSearchParams.get('emailid');
window.HashedEmail = emailid;
Konrad
  • 21,590
  • 4
  • 28
  • 64
  • This looks like a solution. This script will indeed strip data I need. Now - problem never goes alone. Our ESP support informed us that they can not add email hash as an query string at the end of promoted link. They only have merge fields. Is it possible somehow to read e-mail hash from newsletter or to convert email on the fly? Any experience with? – TriviaFem May 11 '22 at 12:57