Show Google Adsense only to searchers
I am not sure whether this is a good idea or not, but I like it and figured out a way doing it by using session.
- First, get to know who is from search engines by checking the referers. There are so many search engines to list that I don't want to match their names into the referers' url. Instead, I thought "?" exists in all these query-like engine search urls. But I saw some "?" is inside some url from msn/live spaces as well. So I switched to check whether "&" is inside or not.
-
if (strpos($_SERVER["HTTP_REFERER"], '&')) { (Your Google Adsense Content) }
- Second, keep the information that the visitor is coming from searching if the visitor finds some other interesting posts within the site and go around, so google ads can be continuously displaced. Since the varible, which keeps the information, needs to go through pages, then it is best to be stored in session. So I do the following
-
if ( strpos($_SERVER["HTTP_REFERER"], '&') ){
-
$_SESSION['ad']=true;
-
} ?>
-
if ($_SESSION['ad']==true) { (Your Google Adsense Content) }
- Third, how about then someone is willing to see the ads and they are not from search engines (who will be that? me, at least, at my own site :p ). So just put another tricky mark in the url to pass the variable to $_GET and then keep the option remembered by session. You may notice from the code, using "?ad=" at the end of url will let you just have google ads once by "?ad=(anything except y)" or for the whole session by "?ad=y"
-
if ( strpos($_SERVER["HTTP_REFERER"], '&') || ($_GET['ad']=='y')){
-
$_SESSION['ad']=true;
-
} ?>
-
if (($_SESSION['ad']==true) || !empty($_GET['ad'])) { (Your Google Adsense Content) }
I didn't use this method here for this blog, but you do can test it at this journal blog here:
Directly use this link: http://www.ohehlium.com/journal/2006/10/01/140/ (no adsense)
Then try google first, and see: Nobel site:ohehlium.com, click this link and go, you will have ads there and you will have it when visiting around unless you close the browser
Or try this link: http://www.ohehlium.com/journal/2006/10/01/140/?ad=1, you will have one time adsense
Or then this one: http://www.ohehlium.com/journal/2006/10/01/140/?ad=y, then the same thing as from search engines
Google Adsense (自称有Sense的广告) at 一亩二分地 on 12 Nov 2006 at 1:05 pm
[...] 广告估计是很多人都想尽力避免的东西了,所以如果有搜索而来访问的(这可是占了60%的大客户呀),喜欢这片一亩二分地并且不想见到广告,大可以加入收藏。当然如果想见到广告,那是更加欢迎,可以点击或收藏这个链接:www.ohehlium.com/journal/?ad=y, 其实也就是在正常链接后加上点东西(具体设置、操作可见Control Adsense visitors)。 [...]