Money-Code

Coding For Online Success

Simple EPN Keyword Tracker for PPC/Organic Searches

| 3 Comments

ebay-partner-networkI’ve discussed in the past on how to capture keywords for EPN store front sites. Basically, if you’re driving traffic with PPC to your store fronts, or even if you’re promoting them with SEO, you’ll want to know what keywords are actually converting them.

To do this, you need to capture the keyword in your site and then pass it as a customid field to eBay. From there you’ll see the keyword in your transaction reports. I’ve worked on my function(s) for this, I still want to tweak them further, but I’ll provide them here so you can play with them in your own application. I want to first explain the general idea of how it retains ‘state’ throughout my site though. If you’re the visitor and clicked on one of my PPC ads (either Yahoo, MSN or Adwords), the referring URL passes some useful information to my site. My function looks for particular information and then determines if it can grab a keyword that was passed from the ad. Each program passes information differently. Once a keyword has been determined, my application then appends that variable (kw) to all links within the site. That way the user can visit multiple areas of my site before going to eBay, and my keyword will follow him.

I’ve considered sticking this in a session or cookie object, but for ease, I left it as a GET or POST variable depending on the situation. I know this part has confused others in the past.

I’ll try to break down the functions below and describe them as best as possible. Please feel free to comment or email me if something doesn’t make sense. This is all written in PHP (compatible with versions 4 or 5).

The first function is the primary getKeyword() function. This function has nested functions since I want to take advantage of code reuse:

function getKeyword(){
        global $attributes, $rootpath;
        $kw                                     = ;
        if(isset($attributes[‘kw’]) && strlen(trim($attributes[‘kw’])) > 0){
                $kw                             = sanitize($attributes[‘kw’]);
        }
        // check yahoo
        if(isset($attributes[‘OVKEY’]) && strlen(trim($attributes[‘OVKEY’])) > 0){
                $kw                             = ‘ysm’.sanitize($attributes[‘OVKEY’]);
        }
        // check handling for msn
        if(isset($attributes[‘a’]) && $attributes[‘a’] == ‘m’){
                if(isset($_SERVER[‘HTTP_REFERER’])){
                        $kw                     = breakQstring($_SERVER[‘HTTP_REFERER’], ‘q’, ‘msn’);
                        if(!strlen(trim($kw))){
                                $kw             = ‘msnUnknown’;
                        }
                }else{
                        $kw                     = ‘msnUnknown’;
                }
        }
        // check handling for google
        if(isset($attributes[‘a’]) && $attributes[‘a’] == ‘g’){
                if(isset($_SERVER[‘HTTP_REFERER’])){
                        $kw                     = breakQstring($_SERVER[‘HTTP_REFERER’], ‘q’, ‘goo’);
                        if(!strlen(trim($kw))){
                                $kw             = ‘gooUnknown’;
                        }
                }else{
                        $kw                     = ‘gooUnknown’;
                }
        }
        if(!strlen(trim($kw))){
                // now ad passed, check for organic
                $kw                             = getKeywordOrganic();
        }
        $kw                                     = eregi_replace("([^a-z0-9]+)",,$kw);
        return urlencode($kw);
}

When I create ads at various PPC networks, I add the following to the URL www.domain.com/a=y. This would pass a=y which would tell my app that the ad is Yahoo.  Once it’s know where it came from it needs to break the querystring and get down to the variable that contains the keyword. That is what the breakQstring() function is about. It requires the referrer, the variable that contains the keyword, and the label for add source. If no keyword is found (because no ‘a’ variable is passed from a ad), it will then check if this is a organic search result with getKeywordOrganic().

function getKeywordOrganic(){
        global $rootpath;
        $retVal                         = ;
        if(isset($_SERVER[‘HTTP_REFERER’])){
                if(eregi(‘google.com’,$_SERVER[‘HTTP_REFERER’])){
                        $retVal         = breakQstring($_SERVER[‘HTTP_REFERER’], ‘q’, ‘orgGoo’);
                // end google check
                }else if(eregi(‘search.yahoo.com’,$_SERVER[‘HTTP_REFERER’])){
                        $retVal         = breakQstring($_SERVER[‘HTTP_REFERER’], ‘p’, ‘orgYah’);
                // end yahoo check
                }else if(eregi(‘bing.com’,$_SERVER[‘HTTP_REFERER’])){
                        $retVal         = breakQstring($_SERVER[‘HTTP_REFERER’], ‘q’, ‘orgBing’);
                }
        }
        return $retVal;
}

getKeywordOrganic looks at the referrer again and looks for the appropriate variable where the keyword is normally found. This function will handle Google, Yahoo and Bing.

function breakQstring($inRef, $inVarCatch, $inType){
        global $rootpath;
        $kw                     = ;
        $xstring        = explode(‘?’,$inRef);
        if(sizeof($xstring) > 0){
                if(isset($xstring[1])){
                        $varstring      = explode(‘&’,$xstring[1]);
                        if(sizeof($varstring) > 0){
                                for($x = 0; $x < sizeof($varstring); $x++){                                     if(isset($varstring[$x][0]) &amp;&amp; $varstring[$x][0] == $inVarCatch){                                               $valstring      = explode(‘=’,$varstring[$x]);                                          if(isset($valstring[1]) &amp;&amp; strlen(trim($valstring[1])) > 0){
                                                        $kw                     = $inType.sanitize($valstring[1]);
                                                        break;
                                                }
                                        }
                                }
                        }
                }
        }
        // clean up
        if(isset($xstring)){    unset($xstring);}
        if(isset($varstring)){  unset($varstring);}
        if(isset($valstring)){  unset($valstring);}
        return $kw;
}

breakQstring() is designed to disassemble the querystring and filter it down to simple variable value pairs and stop when if finds what it’s looking for. If there is a value, it will return the keyword to the parent getKeyword(). I simply call this function and set a local $kw variable. I want to note that I’m using $attributes, you’ll probably need to use $_REQUEST or $_GET or $_POST depending on your situation.

After you have a local $kw variable, you would then pass that to your rover link and add it to the customid field of that link. You should start seeing keywords, search network and organic information in your transaction reports at EPN.

3 Comments

  1. Pingback: PHP for Affiliate Marketers | Money-Code

  2. This is extremely interesting and it’s great of you to share your code and experience.

    A quick question, if you know of the answer… (I’ve been looking quickly through the eBay Developer network docs for this, but without luck so far)…

    If all I want to do is track the referrer code (say, in the customid field) in my rover code, is there a simple paramater I can add to the rover code?

    As in ….. &customid=[http-referrer] or something like that.

    All I would like to do is be able to view the specific referring URL that generated a transaction in EPN reports.

    Many thanks in advance.

  3. Robin.. thanks for commenting!

    I think you could do partial referrer. There is a limit on that field length and not sure what it is. For a while, I thought my keywords (not encoded) was causing problems so I restricted length quite a bit. I would be worried with two items.

    – properly encoding the referrer, you can’t have any ‘weird’ chars in there
    – worried about the length being too long.

    If I was you I would use SEO redirect technique, and then store the referrer in the database before sending them to their destination. You can see more about SEO redirects here: http://www.money-code.com/2007/10/url-masking-cloaking/

    Again, thanks for commenting. Let me know if you have any questions.
    hanji

Leave a Reply

Required fields are marked *.


CommentLuv badge

This site uses Akismet to reduce spam. Learn how your comment data is processed.