URL Parameter on Non-Marketo Landing Pages | Community
Skip to main content
Jenn_DiMaria2
Level 10
December 9, 2013
Solved

URL Parameter on Non-Marketo Landing Pages

  • December 9, 2013
  • 3 replies
  • 2139 views
We are placing Marketo forms on non-Marketo landing pages using the form HTML (not as an iframe).  Will we need to add javascript to our pages to capture the URL Parameters, or can we leave the form set-up as-is and the Marketo code will handle the rest?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by
Hi Jenn, you will need to add some script to you page to capture the URL parameters since your form is on a non-Marketo landing page. The native URL parameter functionality only works if the form is on a Marketo landing page.

3 replies

Accepted solution
December 9, 2013
Hi Jenn, you will need to add some script to you page to capture the URL parameters since your form is on a non-Marketo landing page. The native URL parameter functionality only works if the form is on a Marketo landing page.
Jenn_DiMaria2
Level 10
December 9, 2013
Hi Kate!  That's what I thought, but was hoping it wasn't true :)  Okay, now I know my plan of action.  Thanks!
December 9, 2013
I used this script before the closing </body> tag in the page HTML:

<script type="text/javascript">
 
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
    var cmp = getUrlVars()["cmp"];
 
    if  (cmp != null) {
    $("input#MKTOCampaign").val(cmp);
    }
 
</script>

The name of the field I wanted to pull a value into was MKTOCampaign and the name of our parameter was cmp, so you would want to replace that text with your field ID and URL parameter. I hard-coded the default value into the #MKTOCampaign field on the form HTML that I exported like so:

<input class='mktFormHidden' name="MKTOCampaign" id="MKTOCampaign" type='hidden' value="701E0000000ADt2" />

The script above runs when the page is loaded, and checks to see if there is a cmp parameter in the URL. If there is, it updates the MKTOCampaign field with the new campaign ID from the URL. If there isn't, it keeps the default value that I had initially hard-coded. It worked pretty well!