Google Adsense Ad Unit Counts

In this example, we automatically scan web pages and report if any ad unit, link unit, or search box counts exceed those permitted by the Google Adsense TOS (Terms of Service).

According to the Adsense TOS, you may display up to three ad units, three link units, and two search boxes.  (These limits are subject to change.)  On your web pages, if you mistakenly display more than that, you are in violation of the TOS, which might lead to your expulsion from the Adsense program.  Of course, you will want to be alerted to your non-compliance before that happens.

The AdsenseAdUnitCounts script might send an alert message like the following:

                                PIKT ALERT
                         Tue Dec  6 04:15:29 2005
                                 calgary

WARNING:
    AdsenseAdUnitCounts
        Report ad unit counts violating the Adsense TOS

        /var/www/html/pikt/samples/date_time_macros.cfg.html:
          3 ad units, 4 link units, 1 search boxes
        [...]

The script follows.

#if piktwebsys

AdsenseAdUnitCounts

        init
                status =piktstatus
                level =piktlevel
                task "Report ad unit counts violating the Adsense TOS"

                input proc "=find =piktwebdir -name \\*.html -print
                            -exec =egrep -i 'google_ad_format|search|center|form' {} \\;"

        begin   // initializations
                set $page = ""
                set #adunits = 0
                set #linkunits = 0
                set #searchboxes = 0
#ifdef debug
                set #maxadunits = -1
                set #maxlinkunits = -1
                set #maxsearchboxes = -1
#elsedef
                // these may change
                set #maxadunits = 3
                set #maxlinkunits = 3
                set #maxsearchboxes = 2
#endifdef

        rule    // new page
                if $inlin =~ "^=piktwebdir"
                        if $page ne ""
                                if    #adunits > #maxadunits
                                   || #linkunits > #maxlinkunits
                                   || #searchboxes > #maxsearchboxes
                                        output mail "$page: $text(#adunits) ad units,
                                                            $text(#linkunits) link units,
                                                            $text(#searchboxes) search boxes"
                                endif
                        endif
                        set $page = $inlin
#ifdef debug
                        output $page
#endifdef
                        set #adunits = 0
                        set #linkunits = 0
                        set #searchboxes = 0
                        next
                endif

        rule    // ad unit or link unit
                if $inlin =~ "google_ad_format = $dquote()(.+)$dquote();"
                        set $format = $1
#ifdef debug
                        output $format
#endifdef
                        if $format =~ "^.+_as$"
                                set #adunits += 1
                        elsif $format =~ "^.+ads_al$"
                                set #linkunits += 1
                        endif
                        next
                endif

        rule    // search box; determining this is a bit tricky, because
                // the "<!-- search google -->" marker appears twice in
                // the search box code, so we count just the last instance,
                // signified by the previous line being either "</center>"
                // or "</form>"
                if    $inlin =~~ "<\\!-- (site)?search google -->"
                   && @inlin =~ "(</center>|</form>)"
                        set #searchboxes += 1
                        next
                endif

        end     // last page
                if    #adunits > #maxadunits
                   || #linkunits > #maxlinkunits
                   || #searchboxes > #maxsearchboxes
                        output mail "$page: $text(#adunits) ad units,
                                            $text(#linkunits) link units,
                                            $text(#searchboxes) search boxes"
                endif

#endif  // piktwebsys

(If it really bothers you to see "1 search boxes" instead of "1 search box", you can modify the script to fix that, of course.)

This is just one program example.  You could write new scripts to:  check the value of other fields in the Adsense JavaScript code (example); check to see if you have Adsense on the same page as some other conflicting ad program (example); check the validity of any Adsense section targeting tags (example); and so on.

For more examples, see Samples.

 
Home | FAQ | News | Intro | Samples | Tutorial | Reference | Software
Developer's Notes | Licensing | Authors | Pikt-Users | Pikt-Workers | Related Projects | Site Index | Privacy Policy | Contact Us
Page best viewed at 1024x768 or greater.   Page last updated 2019-01-12.   This site is PIKT® powered.
Copyright © 1998-2019 Robert Osterlund. All rights reserved.
Home FAQ News Intro Samples Tutorial Reference Software
PIKT Logo
PIKT Page Title
View sample
HTML
anchor tag
macros