0

I am running some campaign and would like to get url parameters details submitted with leads/enquiry form to track performance of my campaigns. I am looking for any solution other than php please.

www.example.com?utm_source=Google&utm_medium=CPC&utm_term=Keywords&utm_content=Content&utm_campaign=Promo%20Code

My form will have hidden text fields which should be filled with url parameters above. I.e utm_source

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Nizam
  • 1

4 Answers4

0

You can fill a hidden field like any other field :

$('#my-field').val(newValue);

To get a parameter in the query string of the current location, see this question : How can I get query string values in JavaScript?

With the given function, you can just do this :

$(function() {
    $('#my-field').val(getParameterByName('utm_source'));
});
Community
  • 1
  • 1
Magus
  • 14,796
  • 3
  • 36
  • 51
0

Im not sure if i understand your question. But if you want to use the URL of ur current location you can use

location.toString()
Joonas89
  • 249
  • 1
  • 6
0

You can do it like this:

location.search.substr(1).split('&').forEach(function (entry) {
  var value = entry.split('=');
  document.querySelectorAll('[name=' + value[0] + ']')[0].value = value[1];
});
krolow
  • 201
  • 2
  • 6
0

The only way I know how to do it is by having the form inside a frame. You can get your form response inside that same frame while the displayed URL at the browser address bar will not change.

SunKnight0
  • 3,331
  • 1
  • 10
  • 8