Forum Moderators: coopster

Message Too Old, No Replies

Display Ad Only For Search Engine Referral

         

anand84

6:48 pm on Feb 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all

CTRs have been poor and I want to test displaying an ad block on a middle area of my Wordpress site just for search engine visitors.

Is there any way I can check if the referral traffic is from google.com or news.google.com and display the ad-block only to these visitors?

Thanks

TheMadScientist

9:33 pm on Feb 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if(strpos($_SERVER['HTTP_REFERER'],'google.com')!==FALSE) {
/* Show Ads /*
}

anand84

1:17 pm on Feb 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



@TheMadScientist

Thanks a lot...I just tried it. Replaced 'google.com' with just 'google' so that all its country domains are also covered. While it works well, I just noticed that it doesn't work in Chrome (Also tried it with Firefox and IE). Anyway, it is just a minor issue since not too many people use Chrome.

Also, is there a way to remember the referrer through all the clicks? Because with this particular code, the referral tracking is lost when the user clicks on a link on my site and visits another web page.

TheMadScientist

5:49 pm on Feb 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could store the referrer info in a cookie, not sure on the deal with Chrome.

Change the if a bit if you do:

$CookieSet=0;
if(strpos($_SERVER['HTTP_REFERER'],'google.com')!==FALSE) {
setcookie('CookieName','Google',0,'/','.example.com');
$CookieSet=1;
}

if($CookieSet===1 || (isset($_COOKIE['CookieName']) && $_COOKIE['CookieName']=='Google')) {
/* Show Ads /*
}

anand84

6:13 pm on Feb 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you MadScientist.

Please correct me if wrong. The first 5 lines of code need to be saved in a javascript file and the second set needs to be included in the main page right?

TheMadScientist

6:41 pm on Feb 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Nope, that's all php...

<?php
$CookieSet=0;
if(strpos($_SERVER['HTTP_REFERER'],'google.com')!==FALSE) {
setcookie('CookieName','Google',0,'/','.example.com');
$CookieSet=1;
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="stuffHere" content="An example of Stuff. LOL">
</head>
<body>

<?php
if($CookieSet===1 || (isset($_COOKIE['CookieName']) && $_COOKIE['CookieName']=='Google')) {
/* Show Ads */
}
?>

</body>
</html>

ADDED: You could include it all in a PHP file on all your pages and do something like this:

This would be the include file (showads.php or something)

<?php
$CookieSet=0;
if(strpos($_SERVER['HTTP_REFERER'],'google.com')!==FALSE) {
setcookie('CookieName','Google',0,'/','.example.com');
$CookieSet=1;
}
if($CookieSet===1 || (isset($_COOKIE['CookieName']) && $_COOKIE['CookieName']=='Google')) {
$ShowAds='HTML for Ads Here';
}
?>

Then on your pages:

<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/showads.php'; ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="stuffHere" content="An example of Stuff. LOL">
</head>
<body>

<?php echo $ShowAds; ?>

</body>
</html>

Using the above, if $ShowAds is not set nothing will echo, not showing the ads, and if it is then they will show where ever you put <?php echo $ShowAds ?>

anand84

6:36 pm on Feb 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks a lot..I meant to reply back once I had tried it out. But it somehow slipped out of my things-to-do..

Really appreciate your help..