Personalize returning customer landing page

Source: GraFX 08 March 2009

One of the main principles of marketing is maintaining the visitors, knowing that one makes more efforts to bring new clients rather than to keep existing ones. This way the money they spend is reduced.
We would like to present a possibility on how to keep the existing clients, by customizing the URL they arrive at - the so called “landing page” or “lead capture page” (http://en.wikipedia.org/wiki/Landing_page). In most cases, these pages are used in marketing campaigns, to bring new clients, to measure the efficiency of the campaign, but in this case we are presenting it in a different way - we will focus on the existing clients, those that we have in our databases.
This campaign we present in the example is based on a real case in which at a tourism fair the client has sent invitations to possible customers and for measuring the efficiency of the campaign, has requested to access the URL of the invitation. Further on the customers would have visited their stand and be given discounts and suprise gifts. But let's see what this stands for technically speaking.

Customized URL

If we already have a client that has registered to the site, through a newsletter or by buying something, to 99% of these a welcome mail will be sent, eg: "Welcome Bob Fisher, You have successfully signed up and your account has been established. You are now an active member of “OurCompany”. You can come back any time by visiting http://www.ourcompany.com ...".

Another approach is: "Welcome Bob Fisher, You have successfully signed up and your account has been established. You are now an active member of “OurCompany”. You can come back any time by visiting http://bobfisher.ourcompany.com ...".
You probably noticed the persons name in the URL. Why is this important?

  • because most of them would enjoy having their own URL
  • because when they come back to the page, we can capture their username, and we will know who they are
  • because, if we know who they are, we also know how to customize their page.

Some would now wonder “how is it possible to create thousands of pages, or registrations into DNS zone to do this?”

How can we make it possible technically?

There are some steps that need to be followed, DNS adjustment, Apache modification (the configuration file) and a visit capturing script.

1. Wildcard *DNS:

Mostly of webhosting company will allow to modify DNS from the hosting control panel. All that has to be done is to insert a new A zone.

*.ourcompany.com.  IN A YOUR-IP-HERE

Doing this, you will be able to see that every sub-domain you access, that will redirect you to the home page of your site. Eg: bobfisher.ourcompany.com or markanthony.ourcompany.com, all of these will redirect you to the same URL, initially on www.ourcompany.com.

2. Preparing the Apache configuration file

What do we actually need to do here? We have to capture every visit from a sub-domain – virtual (bobfisher.ourcompany.com, markanthony.ourcompany.com, *.ourcompany.com) and we have to redirect it to a file, like redirect.php. These settings have to be made in the Apache CONF or they may work in .htaccess, directly from the configuration file.
Example.

< VirtualHost YOUR-IP-HERE:80 >
ServerName  www.ourcompany.com
ServerAlias *.ourcompany.com
RewriteEngine on
RewriteCond % !^www.* [NC]
RewriteCond % ^([^.]+).ourcompany.com
RewriteRule ^(.*)   http://www.ourcompany.com/redirect.php?id=% [R,L]
< /VirtualHost >

3. The capturing/redirecting file

What can be done here … there are more possibilities. One of the ideas we used at a the exchibition was to send out customized invitations to all of our guests, with their own personal data and their own URL. Before the exhibition, every guest was added to the database as: ID, shortname – used for the sent URL, name and greeting, language – the site being on multiple languages, and the redirecting being done in the clients’ mother tongue, the access data on the site, the person’s e-mail address, for sending them a “thank you” e-mail for visiting the site and for expressing an interest in our products. This is how the MySOL scheme would look:

CREATE TABLE `user`  (
`id`  int(7) NOT NULL  auto_increment,
`shortname` varchar(250) NOT  NULL,
`fullname`  varchar(200) NOT  NULL,
`salutation` varchar(50) NOT  NULL,
`language`  varchar(3) NOT  NULL,
`data`  datetime NOT NULL default '0000-00-00 00:00:00',
`email`  varchar(200) NOT  NULL,
PRIMARY  KEY  (`id`)
) ENGINE=MyISAM;

This is just one of the examples, depending on what solutions we have, we can use a preinstalled CMS, using the user scheme, or any other solution. For example we can extend with a custom field a CMS where we add the shortname.

When getting to the redirecting Apache file, the first thing we have to do is to start a session (or we may as well set a cookie in the user’s computer with some data), then we replace the URL and take it to our domain name. This way we know whether there is a shortname on the URL, if there isn’t any, we redirect it to www.ourcompany.com.

Let's check firstly the session, include some files, like DB connection, template system (we use Fast Template), a class for mail sending (cls_universal_mailsender.php), and then a class fore users, which will handle the save, delete etc, generated automatically with (PHP Class Generator, based on MySQL table). What is important in this part of the code, is the fact that IF the URL does not have a shortname ($_REQUEST["id"] sent by Apache, redirect.php?id=%), then we redirect to the main page, without doing anything at all.

session_start();
define("INDEX_PATH", dirname(__FILE__)."/");
include_once(INDEX_PATH."include/connection.php");
include_once(INDEX_PATH."include/cls_fast_template.php");
include_once(INDEX_PATH."include/cls_universal_mailsender.php");
include_once(INDEX_PATH."include/cls_user.php");

$from_url = $_REQUEST["id"];
$from_data = str_replace(".ourcompany.com","",$from_url);

if($from_url== "")
header("Location: http://www.ourcompany.com/");
else {..... }

What we can also do now, is to send an e-mail to another person from the company, referring to the fact that the person visited the URL, e-mail message that will contain information about the person, in order to be called later.

	$message = "New visit from url: ".$from_url;

$univMail = new UniversalMailSender("2");
// setting up the to address
$univMail->setToAddress("office@ourcompany.com","OurCompany");
// setting up from address
$univMail->setFromAddress("office@ourcompany.com","OurCompany");
// setting up subject
$univMail->setSubject("New visit from a subdomain");
// setting up from text message if the type is text message
$univMail->setTextMessage($message);
// setting up from text message if the type is html message
$univMail->setHtmlMessage($message);
// sending the mail; returns an error message
$ok = $univMail->SendMail();

The next step is to check whether it is in our database, whether it is a client that we gave out a card to, or it is an attempt from another person. We will receive some data from the database, and if that user exists, we will refresh the ‘data’ field with the new data to see the date of the visit.

$SQL = "SELECT id,fullname,`language` FROM user WHERE shortname='".$from_data."'";
$retid = mysql_query($SQL);
if (!$retid) { echo( mysql_error()); }
if ($row = mysql_fetch_array($retid))
{
$id = $row["id"];
$fullname = $row["fullname"];
$language = strtolower($row["language"]);
}

$_SESSION["session_from_url"] = $from_data;

if(!empty($id))
{
$_SESSION["session_id"] = $id;
$_SESSION["session_fullname"] = $fullname;
$_SESSION["session_language"] = $language;

$user = new User($id);
$user->setShortName($user->getShortName());
$user->setFullName($user->getFullName());
$user->setSalutation($user->getSalutation());
$user->setLanguage($user->getLanguage());
$user->setData(date("Y-m-d H:i:s"));
$user->setEmail($user->getEmail());
$user->save();

Now is time to personalize the email that we will send to our customer. This part of the example is based on Fast Template, you may adapt for your own usage.

$fte = new FastTemplate(INDEX_PATH.$language."/");
$fte->define(array("main"=>"template_welcome_".$language.".html"));
$fte->assign("FULLNAME",$fullname);
$fte->assign("FULLURL",$from_url);
$fte->parse("mainContent", "main");
$message = $fte->fetch("mainContent");

now we will send a “thank you” e-mail message, based on a template (in different languages), to thank him for using the card and for taking interest in our services.

		$univMail = new UniversalMailSender("2");
// setting up the to address
$univMail->setToAddress($user->getEmail(),$fullname);
// setting up from address
$univMail->setFromAddress("office@ourcompany.com","Ourcompany");
// setting up subject
$univMail->setSubject("Ourcompany");
// setting up from text message if the type is text message
$univMail->setTextMessage($message);
// setting up from text message if the type is html message
$univMail->setHtmlMessage($message);
// sending the mail; returns an error message
$ok = $univMail->SendMail();

Final step, we will redirect to index.php page, where we place a variable, to show the user’s name, something like, Welcome Bob Fisher and a short message. The user will be surprised and he would have a good first impression about us. Why do we redirect to index.php and we do not continue in redirect.php code? Because the user should not see at all a redirect.php in the URL. Here again we will check if

@session_start();
if($_SESSION["session_id"] == "") {
header("Location: http://www.ourcompany.com/us/index.php");
exit;

If the session exist, then we will display the page. Now we have here a simplified page, created just for this example. First we load into an array the existing languages.

$lang=strtoupper($_SESSION["session_language"]);
$dear = array("US"=>"Dear","DE"=>"Liebe","NL"=>"Geachte","FR"=>"Cher");

$thankyou = array("US"=>"Thank you for your visiting","DE"=>"Vielen Dank für Ihren Besuch auf","NL"=>"Hartelijk dank voor uw bezoek aan","FR"=>"Nous vous remercions de votre visite a");

$message = array("US"=>"Click here to visit your personal web pages and discover more about smart and
simple solutions for process optimization and to make an appointment After your visit we will automatically
send you your universal travel adaptor. Best regards, The Our Company team","DE"=>"Klicken Sie hier, um Ihre persönliche
Web-Seiten zu besuchen und mehr über Smart einfachen Lösungen für die Prozess-Optimierung und vereinbaren Sie einen Termin.
Nach Ihrem Besuch werden wir automatisch Ihre Universal-Reise-Stecker.

Mit besten Grüßen, Die Our-Company-Team","NL"=>"Klik hier om uw persoonlijke webpagina's te bezoeken en meer te ontdekken over eenvoudige slimme oplossingen voor proces optimalisatie en het maken van een afspraak. Na uw bezoek zullen wij u automatisch uw universele reisstekker toezenden. Met vriendelijke groet, Het Our Company team","FR"=>"Cliquez ici pour vos pages web a visiter et a découvrir des solutions simples a puce pour l'optimisation des processus et de prendre rendez-vous. Apres votre visite, nous vous enverrons automatiquement votre Voyage plug universel. Cordialement, The Our Company team");

Then comes the rest of the HTML code, header and some ... I will not include here the whole header, meta code, please see the source code.

< ?php echo $thankyou[$lang]; ? > < ?php echo $_SESSION["session_from_url"]; ? >.ourcompany.com.

< ?php echo $message[$lang]; ? >

Of course, we may use other ways to do this in other cases, like: if someone comes back to our site and we know what he had bought, we may point out new products for him etc. We could set a cookie for a better security, a cookie we can check for security, the idea being for the user to see that he had visited a sub-domain (bobfisher.ourcompany.com) and for him too feel that he has been treated well.

The full code can be downloaded from redirect_tutorial_byuser.zip