Pass UTM TAGS Webflow page to all links such as other subdomains/sites

<script>document.addEventListener('DOMContentLoaded', function(event) {// create urlParams variable (constant) from URLSearchParams class using current windowconst urlParams = new URLSearchParams(window.location.search);// set UTM medium, source and campaign variables (constants) based on results of URSearchParamsconst utm_medium = urlParams.get('utm_medium') || ""const utm_source = urlParams.get('utm_source') || ""const utm_campaign = urlParams.get('utm_campaign') || ""const utm_term = urlParams.get('utm_term') || ""const utm_content = urlParams.get('utm_content') || ""// get the Outbound button elementlinks = document.querySelectorAll("a");links.forEach(function(outboundLink) { // edit Outbound button element property by appending the URL parameters// idea limit links if outbound matches certain site/domain outboundLink.href += "?utm_medium=" + encodeURIComponent(utm_medium) + "&utm_source=" + encodeURIComponent(utm_source) + "&utm_campaign=" + encodeURIComponent(utm_campaign) + "&utm_term=" + encodeURIComponent(utm_term) + "&utm_content=" + encodeURIComponent(utm_content);}); } );</script>

Based on https://stackoverflow.com/a/65297467

Leave a Reply