If you do any online marketing, you know how difficult it is to track interested visitors through your site. You can get the info from Google Analytics, but it’s a pain.

In our case, we wanted to know the path a visitor took before sending a contact request.

See how you can keep track of this info in a cookie.

1. Set Up a Cookie

When a user first arrives in our website we save a cookie in their browser. The only information we take is the page where the user landed.

We’re using WordPress, so I went ahead and added this to the header.php file,

// check if cookie exists
	// if cookie exists
// concatenate the current URL to their contents into the variable $path
	$path = $_COOKIE['pathcookie'] . $_SERVER['REQUEST_URI'];
else {
	// if cookie doesn’t exist
// add the current URL to the variable $path
	$path = $_SERVER['REQUEST_URI'];
// set up the cookie with the variable $path as the value
setcookie("pathcookie", $path, time()+600, "/", "nearsoft.com");

In the last line, we set up a cookie with the name “pathcookie” with the variable $path as its content. It expires 600 seconds after the current time (10 minutes). And, it’s only valid for our site, nearsoft.com.

2. Save the Breadcrumbs

Every time the user loads a new page we append the URL to the cookie thanks to this part of the previous code,

// if cookie exists
// concatenate the current URL to their contents into the variable $path
$path = $_COOKIE['pathcookie'] . $_SERVER['REQUEST_URI'];


setcookie("pathcookie", $path, time()+600, "/", "nearsoft.com");

3. Send the Breadcrumbs

If the user sends a contact request, we include the content of the cookie in the email we send. To do this, we add a hidden field to our current contact request form,

With that, you have the Post variable path available in whatever you use to send your emails in your system.

The Result should be something like this,


On the other hand, if there’s no contact request the cookie expires in 10 minutes.

Either way the cookie is deleted at the end of the session.


With this simple process we get a piece of information that helps us understand our prospects. And there’s almost no overhead to our website.

If you think this can help you, go for it. It’s really simple to implement.

Just remember: use your powers for good!