Created
March 7, 2024 11:01
-
-
Save Kugelschieber/a20969c07defa771550383e88c6b9444 to your computer and use it in GitHub Desktop.
Tracking links with specific keywords in the URL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p> | |
<a href="https://example.com">Link 1</a> | |
<a href="https://example.com/mountain">Link 2</a> | |
<a href="https://example.com/unreleated">Link 3</a> | |
<a href="https://example.com/sea">Link 4</a> | |
</p> | |
<script> | |
const keywords = [ | |
"sea", | |
"mountain" | |
]; | |
const links = document.getElementsByTagName("a"); | |
for (const link of links) { | |
if (link.hasAttribute("href") && keywords.find(k => link.getAttribute("href").includes(k))) { | |
console.log("Track link", link.getAttribute("href")); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment