Pass URL Parameters to Button

@John_Mooney, you could try running a script when the page loads. This script would:

  1. Unpack the parameters from the URL
    Here’s a link that has a few lines on this. You could likely try this to get the values of the utm_source and utm_medium parameters.
    How to Get URL Parameters with JavaScript - SitePoint

  2. Edit the button link by appending parameters to the end
    I believe something like this would work:

     // get the link element        
     var myLink = document.getElementById("id-of-the-button-link");
    
     // edit its href property by appending the parameters
     myLink.href += "?source=" + sourceParameter + "&medium=" + mediumParameter;
    
     //check
     console.log(myLink.href);
    

This assumes that:

  • Your button is actually a link (and not an HTML form field button)
  • Your URL parameters and values are generally free of punctuation – if they might have spaces or other punctuation, you may need to add some code to ensure that’s handled correctly

Hope this is helpful.

1 Like