preload

Better PPV Target Trimming to Root Domain

Posted by ctrtard on Sep 14, 2011

Using DKI (Dynamic Keyword Insertion) is helpful to increase CTR on your landing pages.

Normally this is a fairly simple task. If you’re using Prosper202 and you’ve got your campaign and tracking setup correctly, 202 should pass your keyword in the URL to your landing page. So you’re landing page URL will look something like this:

http://mydomain.com/landingpage.php?t202kw=walmart.com

To “grab” this keyword and use it in your page, you simply do something like this:

<?php
$target = $_GET['t202kw'];
?>

<h1>Welcome <?php echo $target; ?> Visitors!!!</h1>

(For more about this, check out I don’t get GET’s!)

The Problem

Depending on what target your bidding on in PPV, many times these keywords aren’t “perfect” domains. If So you might end up with something like this:

Welcome ./shoppingcart.walmart.com Visitors!!!

That’s lame.

This Function

…basically trims the target to its root domain and makes it as pretty as possible so you don’t look like a tool to your visitors. I’ve seen a few bits of code floating around that promise to do this for you, but they’ve all done a poor job (a.k.a. suck). Most of them don’t trim subdomains and many of them don’t handle pre-pended and trailing slashes. This one does.

Here’s an example of what this function can do:

http://CTRtard.com = ctrtard.com
https://CtrTard.com = ctrtard.com
http://www.ctrtard.com = ctrtard.com
https://www.ctrtard.com/ = ctrtard.com
/ctrtard.com = ctrtard.com
./ctrtard.com = ctrtard.com
ctrtard.ly = ctrtard.ly
ctrtard.org = ctrtard.org
ww.ctrtard.org = ctrtard.org
//ctrtard.com = ctrtard.com
money.ctrtard.com = ctrtard.com
/ctrtard.com/ = ctrtard.com
//something.ctrtard.com/ = ctrtard.com
//something.ctrtard.com/?morestuff = ctrtard.com

The Code

<?php
function trim_url_to_root_domain($target) {
/** Trim Url to Root Domain
* by ctrtard.com 8/1/2011
*
* This function is mainly useful for PPV. You can pass it a URL (target) and it
* will trim it down to the root domain.  Unlike most other examples I've found,
* It handles subdomains and squirrely, or malformed URLs like "//something.domain.com"
* The result is a nice looking domain for dynamic keyword insertion into your
* landing pages.
*
* Usage:
* echo trim_url_to_root_domain("http://mytarget.com");
* or
* echo ucfirst (trim_url_to_root_domain("http://mytarget.com")); // uppercase first letter
*
*/
    // trim http, https, and //
    $target = str_replace("http:", "", $target);
    $target = str_replace("https:", "", $target);
    $target = str_replace("//", "", $target);

    // check for dots
    $dots = substr_count($target, '.');
    if ($dots > 1) { // if there are more than 1 dots, we need to remove subdomain
        $first_dot = strpos ($target, ".");
        $target = substr($target, $first_dot+1, strlen($target));
    }

    // find the last slash, this should be the slash just before directory info
    $last_slash = strripos($target, "/");
    if ($last_slash > 0 ) {
        $target = substr($target, 0, $last_slash);
    }

    // find last slash one more time, to handle targets like /domain.com
    $last_slash = strripos($target, "/");
    if ($last_slash !== FALSE ) {
        $target = substr($target, 1, strlen($target));
    }

    // normalize target so it's all lower case
    $target = strtolower($target);

    return $target;
}
?>

Usage

I hope most of you know how to use this, but just in case…. Copy & paste this function at the bottom of your LP. Your LP should have a .php extension. To grab the keyword from 202, use the example I gave above. Then, instead of this:

<h1>Welcome <?php echo $target; ?> Visitors!!!</h1>

do this:

<h1>Welcome <?php echo trim_url_to_root_domain($target); ?> Visitors!!!</h1>

That’s it! You can also capitalize the first letter of the domain using PHP’s ucfirst function. Check out the comments in the function for how to do this.

You Break it You Buy It

So far this function has worked pretty well for me, but nobody’s perfect.  If you happen to find a target that doesn’t get trimmed correctly, please post in the comments below and I’ll see what I can do to fix it.

But Wait, There’s More!

I did a guest post on PPV Playbook Blog today called “Killer Buttons To Squeeze More CTR From Your Landing Pages“.  Check it out!

0saves
If you enjoyed this post, it's easy to thank me! Share it using a button on the left, leave a comment or subscribe to my RSS feed. Thanks!

Related posts:

  1. Split Testing and Landing Page Rotation Script for PPV
  2. Tracking202 Missing PPV Icons Fix
  3. Pimp Your Prosper with Subid Injection Buttons
  4. I don’t get GETs!
  5. Split Testing and Rotating Offers in Tracking202

Tags: , , , , ,
  • 37 responses to "Better PPV Target Trimming to Root Domain"

  • Mike Chiasson
    September 14, 2011 4:17 AM 

    Thanks for the share! I’ve thought of implementing a few of these on my broader targets to test but have been too lazy to go grab the code.

    [side note] The lame affbuzz bar things blocks the capability for me to comment on your blog unless I break their frame :)

    • ctrtard
      September 15, 2011 12:44 AM 

      Glad you like the code. Bummer about that affbuzz thing. I’ll have to figure out a workaround. Thanks for the heads up.

  • PeerFly Affiliate Manager
    September 14, 2011 5:22 AM 

    Great script! Thanks for sharing :)

  • windir
    September 14, 2011 10:14 AM 

    This script will only trim correctly if the $target is containing one subdomain section ( ex: one.two.wallmart.com would end up with two.wallmart.com )

    This can be prevented by putting the “check for dots” section in a loop. Removing one dot at the time until only one dot is left.

    That shouldn’t be a big problem tho since there aint a lot of deeper level subdomains than one level normally, but never say never ;)

    • ctrtard
      September 15, 2011 12:45 AM 

      You’re right, it won’t handle 2 subdomains. So far I’ve never used any targets like that, but I guess it’s worth noting. Thanks for reading and commenting!

  • Dan Sapozhnikov
    September 14, 2011 2:11 PM 

    Good stuff. You can also use regex:

    Welcome Visitors!!!

    • ctrtard
      September 15, 2011 12:48 AM 

      Hmm.. I think you may have been trying to include some regex code and WordPress filtered it out. Sorry about that!

      You can indeed use regex for this. I tried some off the shelf regex commands that other people posted but none of them handled all of the target variations I was using so I rolled my own. I suck at regex myself, so I rarely use it.

      Thanks for reading!

  • browie
    September 16, 2011 10:32 PM 

    Glad you wrote again. I don’t understand half of that code so I’ll try and copy/paste :)
    browie’s latest blog post: Over a Month of Work

  • Compound
    September 22, 2011 3:22 PM 

    ctrtard – Thanks once again for another awesome script! One of the guys over at PPVP pointed me to this post.

  • Aysha
    October 07, 2011 12:18 PM 

    I don’t know why its not working for me. Most of the ppv network don’t accept http://www.

    So I removed that command and I’m getting the result for domain.com/aaa/bbb/ccc/ddd like this:

    omain.com/aaa/bbb/ccc

    the first letter missing and the last level of the url

    • ctrtard
      October 08, 2011 3:20 AM 

      There is no need to remove anything. The last directory level is getting chopped off because the script is not expecting more than one slash after the domain. The reason is it’s often silly to bid on targets like that in ppv. Anyone bidding on the domain itself will grab most or all of the traffic.

    • pata33
      March 07, 2012 9:12 PM 

      Thanks so much for this script. I have tried many like it over the last few days and this one is the best!

      Like Aysha, I too have a specific strategy that requires me to bid on very specific long-tail domains that contain many directories and therefore slashes.

      I was able to make a very simple modification to the existing script.

      Find the below code in the existing script…
      ===============================================
      // find the last slash, this should be the slash just before directory info
      $last_slash = strripos($target, “/”);
      if ($last_slash > 0 ) {
      $target = substr($target, 0, $last_slash);
      }

      ================================================

      Replace it with…..
      ================================================

      // find the first slash, this should be the slash just before directory info
      $first_slash = strripos($target, “/”);
      if ($first_slash > 0 ) {
      $target = substr($target, 0, $first_slash);
      }

      // find the second slash
      $second_slash = strripos($target, “/”);
      if ($second_slash > 0 ) {
      $target = substr($target, 0, $second_slash);
      }

      =============================================
      You can repeat this as many times as you like…
      ie. $third_slash, $fourth_slash……

      Seems to work for me. Hope it helps.

  • Alex
    October 10, 2011 11:48 AM 

    ctrtard please help me with this script – I put the code in separate file(http://fill-out-the-survey.com/dc/trim.php). But there is an error “Parse error: syntax error, unexpected T_STRING in /home8/elearnl1/public_html/filloutthesurvey/dc/trim.php on line 23″. I also tried to use this function on landing page – and got the same result.

    • ctrtard
      October 10, 2011 3:13 PM 

      Hi Alex,

      I’m betting you introduced an error when you copy & pasted the script. When you hover your mouse over the code block above, you will see some buttons appear in the top right corner. One of them says “View source”. Click on that and a new window will open. Copy & paste that code into your trim.php file and see if that fixes it.

  • Max
    October 10, 2011 8:05 PM 

    Hi ctrtard,

    Thanks for the wonderful lesson here. Just a quick question though – Which part of my lander do I insert the main code?

  • Robin
    October 31, 2011 3:07 PM 

    Hi, really nice script!

    Could You help me to add additional code for trimming AdOn traffic sources, like, domain.com_113488

    Thanks in advance!

  • Jon
    November 02, 2011 6:59 AM 

    Hi man,
    need your help! for some reason when I am copying this code into the lp it is simply printing out the entire code from 1) { // if there are more than 1 dots, we need to remove subdomain
    $first_dot = strpos…. onwards onto the landing page straight, i am guessing its a verrrry rookie mistake.

    Thanks

    • ctrtard
      November 02, 2011 8:22 AM 

      Does the page you’re pasting into have a .php extension?

      Only pages with a .php are parsed for php code.

  • Jon
    November 02, 2011 7:01 AM 

    forgot to add i am putting in the code between and

  • Jon
    November 02, 2011 9:41 AM 

    Hi, Yea it has a php extension as well.

    • ctrtard
      November 02, 2011 9:48 AM 

      Then you have a typo somewhere or you’ve corrupted the code when you pasted. Hover your mouse over the upper right section of the code block. Then click on the view source icon. Copy & Paste the source code you see.

      Know this: the code works fine. So whatever the problem is, it’s probably something small like a bad paste job.

  • Jon
    November 02, 2011 11:51 AM 

    aaahh u were right it was just a typo in the code i was pasting. thanks for pointing that out :) )

  • Cliff
    November 04, 2011 9:09 AM 

    Could you explain the capitalize the first letter in the domain a little bit more? I had it displaying my target just fine but went to try and have it capitalize the first letter in the domain and things messed up from there and I can no longer even get the keyword to show up. No parse errors, it’s just not pulling the target/keyword through now.

    Any ideas what might cause that? I’ve tried to redo the copy/paste via your buttons. With my own code i have it displaying the keyword/target fine, just can’t get the capitalization part to work.

    • ctrtard
      November 07, 2011 8:22 AM 

      Assuming you are using this code to display your target (and it’s working OK)…

      echo trim_url_to_root_domain($target);

      You can use this code to capitalize the first letter.

      echo ucfirst (trim_url_to_root_domain($target));

  • Jon
    November 05, 2011 11:05 PM 

    Ok so this is working great now! I did see however that bidding on .co.uk domains trims down the display url to just co.uk, is there any way around this? thanks

  • qasy
    November 12, 2011 3:01 AM 

    why don’t you use ‘explode’ function?
    e.g.:

    for the subdomain issues(and UK ones) need only 2 lines more

  • qasy
    November 12, 2011 3:02 AM 

    cutted ot the example:
    domain = explode(“/”,$kw);
    echo $domain[0];

    • ctrtard
      November 28, 2011 11:01 AM 

      You can definitely use explode. But that just gives you an array. You won’t know which array element is which. That’s the problem with handling these types of targets. There are a lot of variations.

      If you make a mod that you think improves on what I have here, feel free to shoot me an email and I’ll post the update. Thanks for reading!

  • mike
    January 08, 2012 1:13 PM 

    This is not working for me, nothing is showing at all. The basic (non-shortening) version works fine.

    I copied the code and the function, so I know they are correct. Files is .php.

    thanks
    mike

  • Adi Rian
    May 02, 2012 11:05 AM 

    Works like a charm. Thanks for this awesome script

    Cheers

    Adi Rian
    Adi Rian’s latest blog post: Easy Way to Create Landing Page Using Photoshop and Dreamweaver

  • Leave a Comment

    * Required
    ** Your Email is never shared
    *

    CommentLuv badge