Capturing PHP subid in WP Blog Posts?

Status
Not open for further replies.

Rob_TID

New member
Jun 24, 2006
1,368
16
0
Ok, so say I have a blog and wanted to do some PPC but want to track down to keyword level.

Therefore I want to pass a sub id from a link within a post.

How do I do that?

I can capture the keyword by putting php in the header:

$keyword=$_GET[keyword];

But then if I try to put a link in a post like such, it doesn't work.

http://affiliatelink.com/&subid=<?PHP echo $keyword;?>

Is there a way to make this work?
 


Great plugin - +rep

However, it still isn't working.

The plugin is installed correctly (hello world executes properly) so I obviously have put the php to capture the variable in the wrong place.

Currently I hav put

<?PHP
$keyword=$_GET[keyword];
?>

in the "header" template, just before the title tag.

Where does it need to go?
 
It looks right what you're doing, but the link is wrong (missing the questionmark):
http://affiliatelink.com/?subid=<?PHP echo $keyword;?>
 
Great plugin - +rep

However, it still isn't working.

The plugin is installed correctly (hello world executes properly) so I obviously have put the php to capture the variable in the wrong place.

Currently I hav put

<?PHP
$keyword=$_GET[keyword];
?>

in the "header" template, just before the title tag.

Where does it need to go?

Try this to see if you are able to get anything....

<?PHP
$keyword=$_GET[keyword];
echo 'keyword: ' . $keyword;
?>
 
I had this same problem before, and although I'm no PHP guru, I was able to use SESSION variables to get it to work. I don't think this is the best way, but it worked for me. You may have to enable session variables in your PHP.ini file or wherever the setup variables are located.

If you don't find a solution and need help with this, PM me.
 
Basic Keyword Tracking

edit: I missed the whole point of the post, but I am going to leave this comment because it could be beneficial to someone.


Basic PHP keyword tracking. I am not completely sure this is what you are trying to do. This script captures the keyword you have bid on yahoo, aol, or Google.

PHP:
$parse = parse_url($_SERVER['HTTP_REFERER']);
$se = $parse["host"];
$raw_var = explode("&", $parse["query"] );
foreach ($raw_var as $one_var) {
$raw = explode("=", $one_var);
$var[$raw[0]] = urldecode ($raw[1]);
}
$se = explode (".", $se);
switch ($se[1]) {
case 'yahoo':
$kw = $var['p'];
break;
case 'aol':
$kw = $var['query'];
break;
default:
$kw = $var['q'];
}

unset($parse, $se, $raw_var, $one_var, $var);
The keyword will be stored in the $KW variable.

Like I said this is very basic, but if you want to track keywords you are bidding on it works for the most part. I did notice that when a yahoo ad is shown on another search engine, the code can't handle the keyword because it doesn't recognize the domain. For those instances you would have to setup another case to match the domain.


With that keyword you could store it in a DB and see what generates clicks, or if you are crafty pass the value to your affiliate company and let them track the conversions for specific keywords (but this is all your getting for free). There is a lot that you can do with the data with some basic php/mysql skill.
 
Is there any reason that putting this code in the header would NOT work (assuming I have the php execute plugin installed)?

<?php
$kw=$_GET[kw];
?>
 
That is to say that the php in the post is definitely executing properly, but the code that captures the keyword in the first place, seems to be the problem.
 
Try something like this.

Code:
<?php 

  // Start Up The Session
  session_start();
  
  // Check to see if the keyword session is set
  if (empty($_SESSION['keyword'])) {
     // Session is not yet set so first determine where the click came from (Google, Yahoo, MSN)
     $refer = $_SERVER['HTTP_REFERER'];

     if(preg_match("/http:\/\/www.google/", "$refer")) {
       // The Click Came From Google So Grab The Keyword
       $subject = "$refer";
       $pattern = '/q=(.*?)&/';          
       preg_match_all($pattern,$subject,$match,PREG_SET_ORDER);
       
       // A Match Had To Of Been Made So Strip Out And Reformat The Keyword.
       $subject = $match[0][0];  
       $replacement = array("q=" => "", "&" => "", "+" => " ", "%20" => "");
       $keyword = strtr("$subject", $replacement);
       trim($keyword);
       
       // Set The Keyword In A Session Var So We Can Use It Only If The User Clicks An Offer
       $_SESSION['keyword'] = $keyword;
     }
     
     if(preg_match("/http:\/\/search.sympatico.msn/", "$refer")) {
       // The Click Came From MSN So Grab The Keyword
       $subject = "$refer";
       $pattern = '/q=(.*?)&/';          
       preg_match_all($pattern,$subject,$match,PREG_SET_ORDER);
       
       // A Match Had To Of Been Made So Strip Out And Reformat The Keyword.
       $subject = $match[0][0];  
       $replacement = array("q=" => "", "&" => "", "+" => " ", "%20" => "");
       $keyword = strtr("$subject", $replacement);
       trim($keyword);
       
       // Set The Keyword In A Session Var So We Can Use It Only If The User Clicks An Offer
       $_SESSION['keyword'] = $keyword;
     }
     
     if(preg_match("/http:\/\/search.yahoo/", "$refer")) {
       // The Click Came From Yahoo So Grab The Keyword
       $subject = "$refer";
       $pattern = '/p=(.*?)&/';          
       preg_match_all($pattern,$subject,$match,PREG_SET_ORDER);
       
       // A Match Had To Of Been Made So Strip Out And Reformat The Keyword.
       $subject = $match[0][0];  
       $replacement = array("p=" => "", "&" => "", "+" => " ", "%20" => "");
       $keyword = strtr("$subject", $replacement);
       trim($keyword);
       
       // Set The Keyword In A Session Var So We Can Use It Only If The User Clicks An Offer
       $_SESSION['keyword'] = $keyword;
     } 
  }
  
?>
 
What part of the blog template would I put it in?

The problem doesn't seem to be the code (it works fine on php pages I build manually), it seems to be where I am placing the capture code in the blog template.
 
Status
Not open for further replies.