Mar 1, 2023

Tag site visitors by page source

Tag users with a page source attribution parameter

This code decorates all links to a certain type of page with an attr parameter telling you which page someone came from.

<script>
var links = document.getElementsByTagName("a");

for (var i = 0; i < links.length; i++) {
  var link = links[i];
  if (link.href.indexOf("/contact") !== -1) {
    link.href += (link.href.indexOf("?") === -1 ? '?' : '&'); 
    link.href += "ref_cta=" + link.innerText.toLowerCase().replace(/[\s,.:;!]/g, "-") + "&ref=" +  window.location.pathname.toLowerCase().replace(/[\s,.:;!]/g, "-");
  }
}
</script>
 Copy
html

We’re *actually* here to help

We’re marketers who love spreadsheets, algorithms, code, and data. And we love helping other marketers with interesting challenges. Tackling the hard stuff together is what we like to do.

We don’t just show you the way—we’re in this with you too.

Background image of a red ball in a hole.