Passing URL vairables via non marketo forms

0 Likes

Passing URL vairables via non marketo forms

Has anyone passed successfully url variables in non-marketo landing pages with forms?

I am trying to figure out how to pass these in a non-marketo landing pages that has a form.   Trying to pass these variables as hidden fields in the forms.


First the url
http://www.yourdomain/?utm_medium=blog&utm_campaign=camptest&SFDCCampaignID=701a000ldlc&CampaignMemberStatus=sent


Here is the javascript


  // to set cookies.  Uses noConflict just in case
  var $jQ = jQuery.noConflict();
 
  <!-- A method from getting the url params using pure javascript.  Taken from http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html-->
 
      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;
    }
    <!-- Then use the fuction to get the param you want. -->
    var params = getUrlVars();
    var utm_medium = params["utm_medium"];
    var utm_source = params["utm_source"];
    var utm_campaign = params["utm_campaign"];
    var SFDCcampaignID = params["SFDCCampaignID"];
    var CampaignMemberStatus" = params["CampaignMemberStatus"];
 
 
   <!-- This should identify the and set the inputs -->
    document.querySelector("input[name='utm_medium']").value = utm_medium;
    document.querySelector("input[name='utm_source']").value = utm_source;
    document.querySelector("input[name='utm_campaign']").value = utm_campaign;
    document.querySelector("input[name='SFDCCampaignID']").value = SFDCCampaignID;
    document.querySelector("input[name='CampaignMemberStatus']").value = CampaignMemberStatus;


and here is the form input fields
    <input type="hidden" name="utm_medium" id="utm_medium"  />
    <input type="hidden" name="utm_source" id="utm_source"  />
    <input type="hidden" name="utm_campaign" />
    <input type="hidden" name="SFDCCampaignID" />
    <input type="hidden" name="CampaignMemberStatus" />

    
  
7 Comments
Anonymous
Not applicable
We always use an iframe call to display a blank Marketo landing page with a Marketo form, which works very well.  We have not tried embedding a Marketo form's html on a non-Marketo page.
Anonymous
Not applicable
Yes, we use a PHP pass thru to a MKTO "destination beacon" of a form and as long as the parameters that you pass are actual fields, it works.
Anonymous
Not applicable
Thanks.   Trying to stay away from the iframe way.   I can't use PHP on the forms though.   I wish it was that easy!  
We have figured out how to pass form info to marketo forms with a non-marketo form.   That is kinda cool.  I will have to post how we got this to work sometime, but hopefully this would be that last part of that post!  

Any other ideas?
Anonymous
Not applicable
Also, the iframe method relies on cookies.  If they have cookie turned off or blocked, this won't work, which is why we try to pass from the url string

Here is the info on passing through a iframe
https://community.marketo.com/MarketoArticle?id=kA050000000L55P&src=comm

Anonymous
Not applicable
John, not sure what you mean by the iframe method relying on cookies.  When we use an iframe call to display a Marketo landing page, we include querystring parameters that are read into hidden fields with information about the context of the non-Marketo landing page from which the Markketo landing page / form was called., but cookies are not required for this to work.
Anonymous
Not applicable
We resolved

<script type="text/javascript">


 
  <!-- A method from getting the url params using pure javascript.  Taken from http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html-->
 
      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;
    }
    <!-- Then use the fuction to get the param you want. -->
    var params = getUrlVars();
    var utm_medium = params["utm_medium"];
    var utm_source = params["utm_source"];
    var utm_campaign = params["utm_campaign"];
    var SFDCCampaignID = params["SFDCCampaignID"];
    var CampaignMemberStatus = params["CampaignMemberStatus"];
 
 

 <!-- This should identify the and set the inputs -->
 $('#utm_medium').val(utm_medium);
 $('#utm_source').val(utm_source);
 $('#utm_campaign').val(utm_campaign);
 $('#SFDCCampaignID').val(SFDCCampaignID);
 $('#CampaignMemberStatus').val(CampaignMemberStatus);
 


  <!-- Test whether or not the input element has the new value set -->
  console.log(utm_medium)
   console.log(utm_source)
  console.log(utm_campaign)
  console.log(SFDCCampaignID)
    console.log(CampaignMemberStatus)
    
</script>
kh-lschutte
Community Manager
Status changed to: Already have it