Skip to content

Instantly share code, notes, and snippets.

@jkereako
Last active June 17, 2022 21:35
Show Gist options
  • Save jkereako/d7d29226cba7287b50f1d1d7939d2772 to your computer and use it in GitHub Desktop.
Save jkereako/d7d29226cba7287b50f1d1d7939d2772 to your computer and use it in GitHub Desktop.
Replace tokenized links with query string arguments.
@jkereako
Copy link
Author

jkereako commented Jun 17, 2022

Description

Replaces tokenized href attributes of all anchor tags on the current page with the corresponding value in the query string. The original purpose is to propagate query string values. It was a hack to support click attribution for an encumbered ad platform.

Example

For the given URL:
http://example.com/mypage?utm_source=foo&utm_campaign=bar

And the given anchor tag on the current page:
<a href="http://asdf.com?utm_source={utm_source}">

This script will output the following:
<a href="http://asdf.com?utm_source=foo">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment