SOLVED

Capture URL parameters and use on links

Go to solution
Anonymous
Not applicable
Hi. I have some landing pages that cannot have forms on them... but they link to other pages with Marketo forms. (It has to be that way, long story.)

On those landing pages, I would like to capture utm parameters from the URL and put it into the links that are on that page.

Is there a way to grab those parameters from the URL and put them into the links on the page?
Tags (1)
1 ACCEPTED SOLUTION
Anonymous
Not applicable
Ah! I got one of my programmers involved, and he devised a bit of code that puts any URL parameters onto every link on the page.

So say "Thanks, Tad" when you use this. Just place it in the "custom meta tags" on a landing page.

<script language="Javascript" src="/js/public/jquery-latest.min.js" type="text/javascript"></script>
<script src="/js/public/jQueryString-2.0.2-Min.js" type="text/javascript" ></script>
<script>
    //Written by Tad from ExploreLearning
if (document.location.search.length) {
jQuery.extend({
  getQueryParameters : function(str) {
 return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
  }
});
$( document ).ready(function() {
    // get qs vars as obj
var qs = $.getQueryParameters();
    //loop all links
    $('a').each(function() {
        //get href
        var hrefParts = $(this).attr('href').split('?');    
        //get copy of qs obj
        var docQS = qs;
        //get href qs vars as obj
        var aQS = $.getQueryParameters(hrefParts[1]);
        //merge together qs objs
        $.extend(docQS, aQS);
        //create new href string
        var newHref = hrefParts[0] + '?' + jQuery.param(docQS);
        //update link href
        $(this).attr('href', newHref);
    });
});
}
</script>

View solution in original post

14 REPLIES 14