Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Javascript: 1st part Checks URL for queries.
    2nd part attaches route function to button with queries add to URL
    You will need to adjust for your URLs.

    ////////1st part
    *Check Query Strings on URLs*
    function getQueryVariable(variable) {
    var query = window.location.search.substring(1)
    var vars = query.split(“&”);
    var blank = “blank”
    for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split(“=”)
    if(pair[0] == variable){
    if(pair[1].indexOf(‘%20’) != -1){
    console.log(pair[1].indexOf(‘%20’))
    var fullName = pair[1].split(‘%20’)
    console.log(fullName)
    return fullName[0] + ‘ ‘ + fullName[1]
    }
    else {
    return pair[1];

    }
    }
    }
    return(false)
    }

    /////////2nd part

    var allqs = location.search;
    var pageBase = “https://yoursite.com/register&#8221; + allqs;
    // var slash = “\/”;
    // var sidVar = “”;

    function leaveFunc() {
    console.log(“outgoingbtn clicked!!”);
    if(allqs == “”){
    console.log(“There are no queries on the URL”);
    allqs = “?provider=somecare”;
    console.log(“Here is the allqs with the default” + allqs);
    pageBase = “https://yoursite/register&#8221; + allqs;
    }else{
    console.log(“Yes, There are queries on the URL”);
    console.log(“allqs is “+ allqs);
    pageBase = “https://yoursite/register&#8221; + allqs;
    }
    window.open(pageBase);
    }

    Thread Starter lukedohner

    (@lukedohner)

    Hi John,
    Wow, you got back to me so quickly!

    Yes, the site uses Cloudflare CDN. I need to have another person clear the cache.
    But does that explain the error coming from the Check Redirect Tool?
    thx Luke

    I ended up using JavaScript. Pasted at the bottom of the page, so after everything loads.

    -ld

    <div>

    <script>
    function getQueryVariable(variable) {
    var query = window.location.search.substring(1)
    var vars = query.split(“&”);
    for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split(“=”)
    if(pair[0] == variable){
    if(pair[1].indexOf(‘%20’) != -1){
    console.log(pair[1].indexOf(‘%20’))
    var fullName = pair[1].split(‘%20’)
    console.log(fullName)
    return fullName[0] + ‘ ‘ + fullName[1]
    }
    else {
    return pair[1];
    }
    }
    }
    return(false)
    }
    //https://mysite.wpengine.com/faqs/learnmore/?sid=00Q1R00001BL44tUAD&utm_source=internal&utm_medium=email&utm_campaign=ems-2019-01-aq-psefaq1a-able-all

    var allqs = location.search;
    var pageBase = “https://en.mysite.com/register/&#8221;;
    var slash = “\/”;

    var sidVar = “”;
    var utm_sourceVar = “”;
    var utm_mediumVar = “”;
    var utm_campaignVar = “”;

    sidrawVar = getQueryVariable(“sid”)
    sidVar = sidrawVar+”/”;
    utm_sourceVar = getQueryVariable(“utm_source”);
    //utm_mediumVar = getQueryVariable(“utm_medium”);
    utm_mediumVar = “web”;
    utm_campaignVar = getQueryVariable(“utm_campaign”);

    console.log(“sidVar is “+ sidVar);
    console.log(“allqs is “+ allqs);
    console.log(“allqs is “+ allqs);
    console.log(“Hello! From the bottom of the WP page”);

    document.getElementById(“learnmore”).onclick = function() {queryFunction()};
    document.getElementById(“learnmore2”).onclick = function() {queryFunction()};
    document.getElementById(“learnmore3”).onclick = function() {queryFunction()};

    function queryFunction() {
    location.href=pageBase + sidVar + “?utm_source=” + utm_sourceVar + “&utm_medium=” + utm_mediumVar + “&utm_campaign=” + utm_campaignVar;
    }
    </script>
    </div>

Viewing 3 replies - 1 through 3 (of 3 total)