@IamJustinM asked the other day

Is it even possible to track visitors and conversions when you have the landing page in an iframe??? Can’t figure it out….

I gave a quick answer, “at top of iframe page, write tracking data to db, then get unique id and use that as your sid w/ the network” but wanted to show it a bit more in detail. So I took 5 minutes I whipped up this quick script:

    // http://yourdomain.com/iframe.php?cSource=google&q=my+keyword
    mysql_connect('server', 'username', 'password');
    $cTable = 'iframetrack';
    CREATE TABLE `iframetrack` (
        `cSource` VARCHAR( 20 ) NOT NULL ,
        `cKeyword` VARCHAR( 200 ) NOT NULL ,
        `cBrowser` VARCHAR( 200 ) NOT NULL ,
        `nIP` VARCHAR( 16 ) NOT NULL ,
        `tsDatetime` DATETIME NOT NULL
    if (empty($_GET['q'])) {
        list(, $cRefererQS) = explode('?', $_SERVER['HTTP_REFERER'], 2);
        parse_str($cRefererQS, $_RefererGET);
        $_GET['q'] = $_RefererGET['q'];
    } // ends if (empty($_GET['q']))
    $cQuery = "insert into $cTable (cSource, cKeyword, cBrowser, nIP, tsDatetime) values ('" . mysql_real_escape_string(stripslashes($_GET['cSource'])) . "', '" . mysql_real_escape_string(stripslashes($_GET['q'])) . "', '" . mysql_real_escape_string(stripslashes($_SERVER['HTTP_USER_AGENT'])) . "', '" . mysql_real_escape_string(stripslashes($_SERVER['REMOTE_ADDR'])) . "', now())";
    $nID = mysql_insert_id();
    $cAffLink = 'http://www.cpaclicks.com/redirect.asp?a=2429&b=27673&d=0&l=0&o=' . $nID . '&p=0';
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="UTF-8" />
<body style="padding:0px; margin:0px;">
    <iframe name="mainsp" id="mainsp" src="<?= $cAffLink ?>" width="100%" height="100%" scrolling="auto" frameborder="0">
          <p><a href="<?= $cAffLink ?>">Click to continue.</a></p>

Now it’s probably not perfect, but it gives you a way to track this info. When you link to this iframe, set cSource to the source of the visitor (can be just the source, or source & ad number combined – whatever) and (optionally) set “q” to the keyword. If you omit this, it’ll look at “q” from the HTTP_REFERER, which is what most search engines use for the keyword field.

I’m not going to go into detail on how to change things – if you need help, just ask.

Leave a Reply

Your email address will not be published. Required fields are marked *