建立一个广告交换及跟踪系统

2016-01-29 17:34 7 1 收藏

建立一个广告交换及跟踪系统,建立一个广告交换及跟踪系统

【 tulaoshi.com - ASP 】

  First you need a database to store your banners. We are using 2 tables; tblBanners and tblVendors:

tblBanners:
bID - auto number (banner ID)
bBanner - text (image file)
bUsedViews - number (# of views the banner has received)
bTotalViews - number (# of impressions the vendor has paid for)
bClicks - number (# of clicks the banner has received)
bURL - text (URL of the site)
bShow - yes/no (used to show and hide banners)
vID - number (vendor ID)

tblVendors:
vID - autonumber (vendor ID - links to tblBanners.vID)
vName - text (Vendor's name)
etc..........


Now that the database is set up, we need to randomly display the banner on our pages and increment the 'views' by 1:

First you need to open your database connection on the page you want your banner to be viewed on. We use a DSN-less connection; you can find it at the following address:

http://www.askasp.com/toolbox.asp?Expand=True&ID=2#tool

Here is what the SQL might look like:

SQL = "SELECT tblBanners.bID, tblBanners.bImage, tblBanners.bUsedViews, tblBanners.bLastViewed "
SQL = SQL & "FROM tblBanners "
SQL = SQL & "WHERE (((tblBanners.bShow)=True) AND ((tblBanners.bTotalViews)[tblBanners].[bUsedViews]));"

In the above SQL, we are checking for the 'bShow' flag to be True, and that the UsedViews is less than the TotalViews.

Now that we have all of the banners that we can display, we need to display a random one. We can do this by grabbing the total number of banners, moving to the first record, and the moving to a random number, for example:


Dim rndMax, rndNumber

Randomize

rndMax = Int(RecordSet.RecordCount)
rndNumber = Int(RND * rndMax)

RecordSet.Move rndNumber


Now that we have moved to our random banner, we now need to display the banner on our page (I am sure you know how to do that, so I wont bore you with the details). However, Instead of using the banner's URL in the link, we are going to use a redirect page so we can count the clicks. All we need to do is use the banner ID in the HREF tag, for example:

a href="redirect.asp?ID=<%= BANNER ID %"

Now that we have the link set up, we can move on to our redirect.asp page. On this page, we are going to grab the ID that we are passing in the Query String, and grabbing the RecordSet that matches. Once we have the RecordSet, we can grab the banner's URL, increase the Clicks by 1, and send the user to the destination URL. Below is the code for the redirect.asp page:

<%
If Request.QueryString("ID") = "" Then
Response.Redirect("default.asp")
End If

Dim varSiteToRedirect, varURLToRedirect

varSiteToRedirect = Int(Request.QueryString("ID"))


SQL = "SELECT tblBanners.bID, tblBanners.bURL, tblBanners.bClicks "
SQL = SQL & "FROM tblBanners "
SQL = SQL & "WHERE (((tblBanners.bID)=" & varSiteToRedirect & "));"

varDatabaseName = "ask_asp_data.mdb"
%

<!--#include file="common/data_conn_open.asp"--

<%
If Not RecordSet.BOF Then
RecordSet.MoveFirst
End If

varURLToRedirect = RecordSet.Fields("bURL")

RecordSet.Fields("bClicks") = (RecordSet.Fields("bClicks") + 1)
RecordSet.Update
%

<!--#include file="common/data_conn_close.asp"--

<% Response.Redirect(varURLToRedirect) %

 

来源:http://www.tulaoshi.com/n/20160129/1501998.html

延伸阅读
===================类的代码========================== {*******************************************************} {                               &n...
标签: Web开发
学习 XML 的最佳途经是从简单的开发入手,大胆实践,循序渐进。XML 的妙处只有在开发过程中才能深入体会,离开了开发是学不好 XML 的。因此学习 XML 首先应该建立一个 XML 的开发环境。我给大家介绍一下怎样建立一个基于 Java 的 XML 开发环境。因为我现在没办法用到 Linux,所以所有的例子都是在 Windows 上做的。但是这里介绍的所有的软件在 ...
标签: PHP
  网路广告,变成了 Internet 上的热门学问。而 468x60 更变成了广告人员绞尽脑汁的尺寸。 在处理广告时,若能直接使用浏览器将广告的 468x60 图档送到处理广告的伺服器中,相信是件很舒服的事,不用再开 FTP 程式,搞大半天只为了 upload。 这个问题,是所有 Web CGI 程式的痛,包括 ASP、Prel....等等,都需要再经过系统元件的增加才...
标签: Web开发
如果要问做什么事是最有吸iPod之外) 它们都很cool, 而且都是很创新的项目。 抛开这些不管,Web设计者们对设计交互式的Web没有什么更好的办法,却对我们做桌面软件的同事投去少许羡慕的目光.桌面应用程序有丰富的界面以及对于Web程序来说无法比拟的响应能力。同样,Web的快速发展,在我们所提供的体验和用户从桌面应用程序所得到的体...
标签: Web开发
借助于DataView,我们便能够为储存于DataTable中的数据建立不同的视图。比方说,通过DataView,您可以使用不同的排序顺序检视DataTable中的数据,亦或是根据数据列状态或筛选表达式来筛选DataTable中的资料。重要的是,当我们需要替DataTable中的数据建立不同的视图而且需要将这些数据绑定到窗体上的控件时,更需要使用DataView来完成。 ...

经验教程

45

收藏

88
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部