Adsense Section Targeting
In this example, we automatically scan web pages and report any errors with Adsense section targeting.
The Google Adsense program attempts to match ads to page context, but doesn't always get it right. To help the Adsense ad matching AI, you can use "hints" to emphasize or downplay sections of page text. These "hints" take the form of HTML comments.
For example, to emphasize a section of HTML content, you might do this:
<!-- google_ad_section_start --> [...] <!-- google_ad_section_end -->
To downplay a section of HTML content, you might do this:
<!-- google_ad_section_start(weight=ignore) --> [...] <!-- google_ad_section_end -->
If your CMS (Content Management System) or your hand editing of web pages has mistakenly omitted or mangled a section targeting tag, or ordered them out of sequence, you might mislead the Adsense ad matching AI, making ads more off-target than on-target. You would want to be alerted to any misuse of section targeting, of course.
The ReportAdsenseSectionTargeting script might send an alert message like the following:
PIKT ALERT
Sat Dec 31 06:38:59 2005
calgary
WARNING:
ReportAdsenseSectionTargeting
Report any errors with Adsense section targeting
/var/www/html/pikt/todo.html: =ignorestart tag without preceding end tag
[...]
/var/www/html/pikt/links.html: invalid tag: <!-- google_ad_section_begin -->
[...]
The script follows.
#if piktwebsys
ReportAdsenseSectionTargeting
init
status =piktstatus
level =piktlevel
task "Report any errors with Adsense section targeting"
input proc "=find =piktwebdir -name \\*.html -print
-exec =egrep google_ad_section {} \\;"
rule // new page
if $inlin =~ "^=piktwebdir"
// final start tag with no following end tag
if @inlin eq "=ignorestart"
|| @inlin eq "=emphasizestart"
output mail "$page: start tag without following end tag"
endif
set $page = $inlin
next
endif
rule // =emphasizestart tag without preceding end tag
if $inlin eq "=emphasizestart"
if @inlin eq "=emphasizestart"
|| @inlin eq "=ignorestart"
output mail "$page: \=emphasizestart tag without
preceding end tag"
endif
next
endif
rule // =ignorestart tag without preceding end tag
if $inlin eq "=ignorestart"
if @inlin eq "=ignorestart"
|| @inlin eq "=emphasizestart"
output mail "$page: \=ignorestart tag without
preceding end tag"
endif
next
endif
rule // end tag without preceding start tag
if $inlin eq "=emphasizeend"
// || $inlin eq "=ignoreend"
if @inlin ne "=emphasizestart"
&& @inlin ne "=ignorestart"
output mail "$page: end tag without
preceding start tag"
endif
next
endif
rule // invalid tag
output mail "$page: invalid tag: $inlin"
end // final start tag with no following end tag
if $inlin eq "=ignorestart"
|| $inlin eq "=emphasizestart"
output mail "$page: start tag without following end tag"
endif
#endif // piktwebsys
The script makes use of several section targeting macros defined in our macros.cfg file as follows:
// Adsense section targeting emphasizestart <!-- google_ad_section_start --> emphasizeend <!-- google_ad_section_end --> ignorestart <!-- google_ad_section_start(weight==_ignore) --> ignoreend <!-- google_ad_section_end -->
So, for example, we might use section targeting macros as in
=ignorestart <div id="header"> [...] </div> =ignoreend
It is much more convenient, and we are much less likely to make a mistake, using (for example) "=ignorestart" in our page source code than entering its equivalent, "<!-- google_ad_section_start(weight=ignore) -->".
Since the =emphasizeend and =ignoreend comment strings are identical, we were able to simplify sections of the script code.
This is just one program example. You could write new scripts to: check the value of other fields in the Adsense JavaScript code (example); make sure that you have not violated the Adsense rules about total ad units (example); and so on.
For more examples, see Samples.