Home > Articles > Web Development

  • Print
  • + Share This

Simple Web Page Commercial, Version 2

With just a couple of changes, we can transform our commercial script (adcheck.asp) so that it only displays the commercial, centered in the middle of the screen, along with a message asking users to visit the advertiser to help keep the site going.

In preparation for displaying just the commercial, follow these steps:

  1. Add an end-percent symbol before the response.write statement.

  2. Add a begin-percent symbol after the response.write statement (see Listing 15)

Listing 15 - adcheck.asp: Code to Display an Ad After 10 Page Views

<%
'
' Initialize the cookie
'
if request.cookies("pagecount")="" then
 response.cookies("pagecount")=0
end if
'
' Increment the page count by 1
'
v_pagecount=CINT(request.cookies("pagecount"))
v_pagecount=v_pagecount+1
response.cookies("pagecount")=v_pagecount

v_adcode="<a href=""http://www.qksrv.net/click-814820-1932310"" " & _
     "target=""_top"" > "                   & _
     "<img src=""http://www.qksrv.net/image-814820-1932310"" " & _
     "width=""468"" height=""60"" "              & _
     "alt=""Last Minute Travel Deals"" border=""0""></a>"
'
' Display advertisment after 10 page views
'
v_frequency=10
IF (v_pagecount MOD v_ frequency)=0 THEN
%>
 response.write(v_adcode)
<%
END IF
%>

We'll replace the response.write with HTML that centers the ad on the web page. The general format for this code looks like Listing 16:

Listing 16 - General Code for Centering an Ad in the Middle of the Screen

<HTML>
<HEAD>
<TITLE>A word from our sponsors</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH=100% HEIGHT=100%>
<TR><TD ALIGN=CENTER VALIGN=CENTER>
 <%=v_adcode%>
</TD></TR>
</TABLE>
</BODY>
</HTML>

Note the <%=v_adcode%>, which displays the ad. To this code, we add a simple incentive to click the banner. This incentive is just a sentence asking our users to help keep the site free by visiting the advertiser (see Listing 17):

Listing 17 - Adding an Incentive to Click the Ad

<HTML>
<HEAD>
<TITLE>A word from our sponsors</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH=100% HEIGHT=100%>
<TR><TD ALIGN=CENTER VALIGN=CENTER>
<B>Please help keep this site free by visiting our advertisers</B>
<BR><BR>
 <%=v_adcode%>
</TD></TR>
</TABLE>
</BODY>
</HTML>

But we're not done. As mentioned earlier, most advertisers don't like you forcing users to click ads. You need to give the user the option of continuing to the web page he or she intended to view. You can use request.servervariables("script_name") together with the <A> tag to link to the proper web page (see Listing 18):

Listing 18 - Adding the Option to Continue to the Web Page

<HTML>
<HEAD>
<TITLE>A word from our sponsors</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH=100% HEIGHT=100%>
<TR><TD ALIGN=CENTER VALIGN=CENTER>
<B>Please help keep this site free by visiting our advertisers</B>
<BR><BR>
<%=v_adcode%>
<BR><BR>
Otherwise click <A HREF="<%=request.servervariables("script_name")%>">
here</A> to continue
</TD></TR>
</TABLE>
</BODY>
</HTML>

request.servervariables("script_name") returns the name of the file hosting the include file, such as commercialpage.asp.

Time to try it:

  1. Add the code above in place of the response.write in Listing 15 (see Listing 19):

    Listing 19 - Centered Ad, with Incentive and Options

    <%
    '
    ' Initialize the cookie
    '
    if request.cookies("pagecount")="" then
     response.cookies("pagecount")=0
    end if
    '
    ' Increment the page count by 1
    '
    v_pagecount=CINT(request.cookies("pagecount"))
    v_pagecount=v_pagecount+1
    response.cookies("pagecount")=v_pagecount
    
    v_adcode="<a href=""http://www.qksrv.net/click-814820-1932310"" " & _
         "target=""_top"" > "                   & _
         "<img src=""http://www.qksrv.net/image-814820-1932310"" " & _
         "width=""468"" height=""60"" "              & _
         "alt=""Last Minute Travel Deals"" border=""0""></a>"
    '
    ' Display advertisment after 10 page views
    '
    v_frequency=10
    IF (v_pagecount MOD v_ frequency)=0 THEN
    %>
    <HTML>
    <HEAD>
    <TITLE>A word from our sponsors</TITLE>
    </HEAD>
    <BODY>
    <TABLE WIDTH=100% HEIGHT=100%>
    <TR><TD ALIGN=CENTER VALIGN=CENTER>
    <B>Please help keep this site free by visiting our advertisers</B>
    <BR><BR>
    <%=v_adcode%>
    <BR><BR>
    Otherwise click <A HREF="<%=request.servervariables("script_name")%>">
    here</A> to continue
    </TD></TR>
    </TABLE>
    </BODY>
    </HTML>
    <%
    END IF
    %>
  2. However, the code is incomplete. We still haven't solved the problem of displaying just the commercial and not the message. To solve this problem, change the END IF at the bottom of the file to an ELSE.

Your completed adcheck.asp script should look as follows (see Listing 20):

Listing 20 - adcheck.asp: Final Version

<%
'
' Initialize the cookie
'
if request.cookies("pagecount")="" then
 response.cookies("pagecount")=0
end if
'
' Increment the page count by 1
'
v_pagecount=CINT(request.cookies("pagecount"))
v_pagecount=v_pagecount+1
response.cookies("pagecount")=v_pagecount

v_adcode="<a href=""http://www.qksrv.net/click-814820-1932310"" " & _
     "target=""_top"" > "                   & _
     "<img src=""http://www.qksrv.net/image-814820-1932310"" " & _
     "width=""468"" height=""60"" "              & _
     "alt=""Last Minute Travel Deals"" border=""0""></a>"
'
' Display advertisment after 10 page views
'
v_frequency=10
IF (v_pagecount MOD v_ frequency)=0 THEN
%>
<HTML>
<HEAD>
<TITLE>A word from our sponsors</TITLE>
</HEAD>
<BODY>
<TABLE WIDTH=100% HEIGHT=100%>
<TR><TD ALIGN=CENTER VALIGN=CENTER>
<B>Please help keep this site free by visiting our advertisers</B>
<BR><BR>
<%=v_adcode%>
<BR><BR>
Otherwise click <A HREF="<%=request.servervariables("script_name")%>">
here</A> to continue
</TD></TR>
</TABLE>
</BODY>
</HTML>
<%
ELSE
%>

That's it for adcheck.asp! Note, however, that every ELSE statement should have a corresponding END IF. We'll add the END IF to another include file, which we'll name adcheckx.asp.

  1. In your text editor, type the following on a single line:

  2. <% end if %>
  3. Save the file as an ASP script named adcheckx.asp.

Your file should look as follows (see Listing 21):

Listing 21 - adcheckx.asp: Just One Line of Code

<% end if %>

Next, we re-instrument the page we want the commercial to appear in, with our new code.

Adding the Commercial Code (Version 2)

Instrumenting a file to handle the new version of the web page commercial code is a simple matter of including adcheck.asp to the top of that file and adcheckx.asp to the bottom of the file. The source file for our web page already has adcheck.asp included at the top. We add adcheckx.asp to the bottom as shown in Figure 10.

Figure 10 commercialpage.asp: adcheckx.asp added to the bottom of the file.

In short, the general procedure for adding a commercial to any web page is shown in the following steps (here using adcheck.asp and adcheckx.asp as the examples):

  1. Include adcheck.asp at the top of the source file for that web page, after any other include files you may have at the top.

  2. Include adcheckx.asp at the bottom of the source file for that web page, before any other include files you may have at the bottom.

Let's test our web page.

Testing the Commercial

We assume a link page exists. If you display this page in a browser it looks as follows (see Figure 11):

Figure 11 linkpage.asp displayed in a browser.

If you click the Click here link, the first nine times you see the page without a commercial (see Figure 12). Every tenth time, however, the advertisement is displayed (see Figure 13).

Figure 12 commercialpage.asp: No commercial displayed the first nine times it's viewed.

Figure 13 commercialpage.asp: Commercial displayed every tenth time the user views the page. The commercial includes an incentive to click (top of the ad) and an option to continue (bottom of the ad).

This time, the "Hello World" message isn't displayed. The user is also given the option of continuing to the web page by clicking the here link (refer to Figure 12).

And that's it for web page commercials. My next article looks at driving traffic to your web site and other online marketing issues (see Figure 14).

Figure 14 Autonomous business model, marketing section highlighted with dashed lines.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.