Creating PURLs On The Fly

Creating Personalized URLs (PURLs) On The Fly is a great money-saving tactic for marketers with a large contact database. (Typically > 1 Million)

PURLs On The Fly

I came up with this tactic after a prospective client came to me wanting to take advantage for USPS’s PURL Promotion.  They have a database of 6 Million contacts, and it simply wouldn’t make sense to transfer this data into Purlem, let along pay up-front for 6 Million PURLs. Creating PURLs on the fly would allow for this user to only pay for contacts that actually visited their PURL!

There are two major catches:

  1. The level personalization on the PURL landing page can’t go beyond the contact’s first and last name (because that is all we know about the visitor)
  2. It will be up to you to de-dup the contacts.

For example, if there are two “Joe Smiths” in your database, you will need to make them unique.  This could be as simple as adding a number to the end of their PURLs:

domain.com/Joe.Smith1
domain.com/Joe.Smith2

With that, you can simply send the de-duped PURLs to your print provider or email service. There is no need to first upload (and pay for) your contacts into Purlem.

Setting up PURLs On The Fly

The setup for PURLs On The Fly can be a bit technical. If you need assistance with getting this setup, please contact us.  But if you’d like to give it a try yourself, this is how to do it…

Insert unknown contact through Purlem’s API

You will need to work with through Purlem’s API to automatically add contacts into Purlem that do not yet exist.  The code to do that is below. Add this code to your landing page (index.php) file, just below the existing PURL CODE.

You’ll also want to download the purlapi.php, and add it to your server.

if($visitor->firstName == '') {
 require '../purlapi.php';
 $firstName = $_GET['first'];
 $lastName = preg_replace('/[^\\/\-a-z\s]/i', '', $_GET['last']);
 $dupID = preg_replace('/\D/', '', $_GET['last']);

 /************************************
 ******* Enter Your Info Here ********
 ************************************/
 $userID = 'xxxx'; //Enter your userID here
 $token = 'xxxxxxxxxxxxxxxx'; //Enter your API Token here
 $campaignID = 'xxxx'; //The campaign that you would like to add the contact to
 /************************************/
 
 //Connect
 Purlem::connect($userID,$token);
 
 // Add Contact 
 $data = array(
 'campaignID' => $campaignID,
 'firstName' => $firstName,
 'lastName' => $lastName,
 'customXXXX' => $dupID //the custom field to store the duplicate ID
 );
 
 $response = Purlem::add_contact($data);
 $response = json_decode($response);

 //Error
  if($response->code == 400) {
  $error = $response->message;
 }

 //Success
 else {
  //Redirect to PURL (Optional)
  header( 'Location: http://'. $response->data->purl ) ;
  exit;
 }
}

Define First and Last Name

Next you’ll want to add the following just above the existing PURL CODE to define the first and last name:

if($_GET['name']) $name = $_GET['name'];
if($_GET['first']) $name = $_GET["first"].$_GET["last"];

Modify .htaccess file

Every Purlem campaign uses the .htaccess file to redirect the PURL to the proper landing page. PURLs On The Fly request slight modification of this code.  Find the following line:

RewriteRule ^([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]+)/?$ http://domain.com/purlpage/index.php?name=$1$2&ID=2764&page=1 [R,L]

And replace with:

RewriteRule ^([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]+)/?$ http://domain.com/purlpage/index.php?first=$1&last=$2&ID=2764&page=1 [R,L]

——

And that’s it!  When a PURL is visited, if it doesn’t already exist in Purlem, a new contact will be added and tracked.  Pretty slick huh?