Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
?>
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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

share|improve this answer
    
It worked, but I'm finding that the session does not stick when moving between pages. Is there a reason for that? –  Zach Shallbetter Jul 12 '11 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. –  mitchellhislop Jul 13 '11 at 14:34
    
I updated the post with my current findings. –  Zach Shallbetter Jul 13 '11 at 16:39
    
Any thoughts on this Mitchell? –  Zach Shallbetter Jul 19 '11 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. –  mitchellhislop Jul 26 '11 at 13:54
add comment

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.

share|improve this answer
1  
This is specifically for Sales, they need to see the information in the form that is submitted. Using Analytics will not cover it. –  Zach Shallbetter Jul 12 '11 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. –  mitchellhislop Jul 12 '11 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]; –  Zach Shallbetter Jul 12 '11 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. –  mitchellhislop Jul 12 '11 at 20:03
    
lol, if you put that in an answer I'll check it. –  Zach Shallbetter Jul 12 '11 at 20:10
add comment

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.