How do I retain url parameters the entire time a user browses my site?

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.

Read More

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
?>

Related posts

Leave a Reply

2 comments

  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. –

  2. 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.