I'm trying to track only the queries that result in AdSense clicks, but not in all queries. The PHP to MySQL part is easy and I've figured out how to use JavaScript to identify the AdSense ads and triger a function on onClick. I'm stuck at the part with how to call the PHP page with that function.
Anyone have any ideas? Here's what I have so far:
PHP Code:
<script type="text/javascript">
<!--
// THIS CODE MUST BE **AFTER** THE GOOGLE CSE CODE
function adSenseClick() {
// WHAT GOES IN HERE?
// It needs to send: "/AdSenseTracker.php?Query=blue%20widgets&Destination=http://widgets.com/blue.html"
}
function load1 () {
var AdSense = window.frames["googleSearchFrame"].document.getElementById('pa1');
if (AdSense)
AdSense.onclick = adSenseClick;
}
function load2 () {
var AdSense = window.frames["googleSearchFrame"].document.getElementById('pa2');
if (AdSense)
AdSense.onclick = adSenseClick;
}
function load3 () {
var AdSense = window.frames["googleSearchFrame"].document.getElementById('pa3');
if (AdSense)
AdSense.onclick = adSenseClick;
}
function load4 () {
var AdSense = window.frames["googleSearchFrame"].document.getElementById('pa4');
if (AdSense)
AdSense.onclick = adSenseClick;
}
function load5 () {
var AdSense = window.frames["googleSearchFrame"].document.getElementById('pa5');
if (AdSense)
AdSense.onclick = adSenseClick;
}
function load6 () {
var AdSense = window.frames["googleSearchFrame"].document.getElementById('pa6');
if (AdSense)
AdSense.onclick = adSenseClick;
}
function doload () {
if (document.getElementsByTagName &&
document.getElementsByTagName ('body')) {
load1 ();
load2 ();
load3 ();
load4 ();
load5 ();
load6 ();
}
}
window.onload = doload;
//-->
</script>