1

We have customers that come from other sites and I would like to retain a url parameter /?lead=openeye throughout the time that they're browsing. That way when they fill out a form I can capture the lead for sales.

How do I retain url parameters the entire time they're browsing the site.

Update..

I've began using a combination of sessions and cookies to accomidate this. It sort of works but doesn't seem to stick for more than a few seconds between pages.

In the header

<?php 
    $lead = $_GET['lead']; $_SESSION['lead'] = $lead;
    $url = parse_url(get_bloginfo('url'));
    setcookie("lead", $lead, 0, $url['path'], $url['host']); (set) 
?>

To test

<?php 
    echo ($_COOKIE['lead']); // Lead Cookie
?>

2 Answers 2

1

Better Answer:

session_start(); $lead = $_GET['lead']; $_SESSION['lead'] = $lead;

Then, create an additional field on the form, with the input hidden. For the value, I would echo out the $_SESSION, with a name that is easy to grab (lead works). then, wherever the form is processed, just add a line to grab the lead, and do with it what you want. –

6
  • It worked, but I'm finding that the session does not stick when moving between pages. Is there a reason for that? Jul 12, 2011 at 21:08
  • Dont call session_start on each page - you are clearing out the session then. It should only be called once, and you might be able to avoid calling it altogether. Jul 13, 2011 at 14:34
  • I updated the post with my current findings. Jul 13, 2011 at 16:39
  • Any thoughts on this Mitchell? Jul 19, 2011 at 19:46
  • Just figured it out - set the cookie to a longer expires. PHP.net says that lasts until the browser closes, but if you make it last longer, like 30 min (time()+60*30), you might have better luck. Jul 26, 2011 at 13:54
0

The best way to do that is to capture the query with a tool like Google Analytics, and set up your site to also track the form with it.

there really is not a good way to do it - meaning that I cannot think of any. It is best to use tools meant for the job.

Setup Google Analytics, and set your form up as a conversion goal.

Once people start to convert, you can see where they came from.

You could go a step further and log a custom variable in GA that will store the lead.

This method is much better, well supported, and removes any chance of tampering.

5
  • 1
    This is specifically for Sales, they need to see the information in the form that is submitted. Using Analytics will not cover it. Jul 12, 2011 at 18:43
  • You could also store the value in a session variable as they come into the site, and add it to the form content when it is getting submitted in a hidden field. Jul 12, 2011 at 18:44
  • that's a good point as well. Would you mind answering with specifics on how you would store and output the variable? I imagine it would be something like session_start(); $lead = $_GET['lead']; $_SESSION['lead'] = $lead; $_POST[$lead]; Jul 12, 2011 at 19:09
  • Up until the post, that is exactally right. However, I would create an additional field on the form, with the input hidden. For the value, I would echo out the $_SESSION, with a name that is easy to grab (lead works). then, wherever the form is processed, just add a line to grab the lead, and do with it what you want. Jul 12, 2011 at 20:03
  • lol, if you put that in an answer I'll check it. Jul 12, 2011 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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