1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Inject Search Term To Web Page To Optimize Ads

Discussion in 'PHP & Perl' started by Androx, Mar 23, 2011.

  1. Androx

    Androx Newbie

    Joined:
    Dec 26, 2010
    Messages:
    15
    Likes Received:
    6
    Location:
    Japan
    When people land on your page from a search engine it may help to optimize Ads based on their search keywords.

    For example, I believe that Ad$ense responds to the nearby keywords on a page. So you can insert the keywords dynamically near to the Ad unit. Ordinarilly you don't need to do this, but if your page is a bit general in nature, it may help.

    Here is some code that I dug out from one of my sites:

    PHP:
    $subject getenv("HTTP_REFERER");
    if (
    strpos($subject'search') > 0){
    $pattern '/q=([^&]+)/';
    preg_match($pattern$subject$matches);
    if (
    $matches){
        
    $r $matches[1];
    } else {
        
    $pattern '/p=([^&]+)&/';
        
    preg_match($pattern$subject$matches);
        if (
    $matches){
            
    $r $matches[1];
        } else {
            
    $pattern '/query=([^&]+)&/';
            
    preg_match($pattern$subject$matches);
            if (
    $matches){
                
    $r $matches[1];
            } else {
                
    $r '';
            }
        }
    }
    $keyword str_replace('+',' ',$r);
    $keyword str_replace('%20',' ',$keyword);
    $kw strtolower(str_replace(' ','-',trim($keyword)));
    $keyword ucwords($keyword);
    This code is a bit old now, but hopefully it still works. Basically it gives you a keyword string to use to formulate a paragraph of text above the Ad.

    Better still may be to store the previous say 10 search terms and display them in a list e.g. visitors recently landing on this page were looking for ...
    Then the keyword update is smoothed over more.

    Maybe you guys have some other ways to achieve this to share in this thread?
     
  2. DisavowedKing

    DisavowedKing Regular Member

    Joined:
    Sep 1, 2010
    Messages:
    243
    Likes Received:
    84
    Gender:
    Male
    Occupation:
    Marketing - Email, Direct Mail, and Internet
    Location:
    San Diego, CA
    Do you know if this works still? Confused as to what I should echo into my content to show the keywords.