0

I'm doing some conversion and revenue tracking using Virtual Website Optimizer. To track revenues, they instruct you to add a piece of Javascript code on the thank you page to determine the actual revenue earned.

<script type="text/javascript">
var _vis_opt_revenue = 0;
//zero should be replaced by the actual revenue figure
</script>

I'm using a Wufoo form and made it so that I can add a URL parameter that totals up their order, so for example if their order has a total of $280 they'll be sent to:

http://mysite.com/thank-you?total=280

I'm wondering: how can I make it so that URL parameter is inserted into the Javascript tracking code from Visual Website Optimizer?

Thanks in advance.

cdotfeli
  • 309
  • 1
  • 4
  • 14
  • 1
    possible duplicate of [Get query string values in JavaScript](http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript) – Felix Kling Aug 04 '12 at 10:45

2 Answers2

3

Function taken from here

Add this

function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

Then change

var _vis_opt_revenue = 0;

to

var _vis_opt_revenue = getParameterByName("total");
Community
  • 1
  • 1
Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • Should should vote to close the question as duplicate if you can answer it with an existing answer. But I guess you know that... – Felix Kling Aug 04 '12 at 10:45
  • @FelixKling hmm, I added content which the OP might not know (using the function). – Dogbert Aug 04 '12 at 10:51
  • Thanks, that helped. And yes, it was useful -- I didn't know how to use the function itself. Using document.write it displays the parameter, so this might work. – cdotfeli Aug 05 '12 at 00:16
  • this does look right. But is it the only way the value is passed over to the page? – Neo Aug 06 '12 at 07:11
0

Try this

var _vis_opt_revenue = 
         '$' + window.location.pathname.split('?')[1].split('=')[1];
yogi
  • 19,175
  • 13
  • 62
  • 92