Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
1  
possible duplicate of Get query string values in JavaScript –  Felix Kling Aug 4 '12 at 10:45

2 Answers 2

up vote 3 down vote accepted

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");
share|improve this answer
    
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 4 '12 at 10:45
    
@FelixKling hmm, I added content which the OP might not know (using the function). –  Dogbert Aug 4 '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 5 '12 at 0:16
    
this does look right. But is it the only way the value is passed over to the page? –  Neo Aug 6 '12 at 7:11

Try this

var _vis_opt_revenue = 
         '$' + window.location.pathname.split('?')[1].split('=')[1];
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.