Tracking Ad Clicks with AdRotator
 | |
| Figure 3. The images used by the AdRotator control are stored in a new Images folder. |
Next you need to manipulate the
AdRotator control. The
AdRotator control displays advertisements randomly based on an XML file you specify. The XML file contains a list of images and links for various advertisements. Set the
AdvertisementFile property of the
AdRotator control to '
~/advertisements.xml' and the
CountClicks property to True. Leave the
RowsPerDay property as -1 (default). A value of -1 will use a single row per day to store the click counts.
<asp:AdRotatorID="AdRotator1" Runat="server"
AdvertisementFile="~/advertisements.xml"
CountClicks="True" />
Here is my
advertisements.xml file:
<?xmlversion="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/images/twintower.jpg</ImageUrl>
<NavigateUrl>http://www.amazon.com/exec/obidos/ASIN/B0002JUXE2
</NavigateUrl>
<AlternateText>Twin Towers</AlternateText>
<CounterGroup>BannerAdvertisement</CounterGroup>
<CounterName>TwinTower</CounterName>
</Ad>
<Ad>
<ImageUrl>~/images/nationalgeographic.jpg</ImageUrl>
<NavigateUrl>http://www.amazon.com/exec/obidos/ASIN/B0002CHIME
</NavigateUrl>
<AlternateText>National Geographic - Roar: Lions of the Kalahari
</AlternateText>
<CounterGroup>BannerAdvertisement</CounterGroup>
<CounterName>NationalGeographic</CounterName>
</Ad>
</Advertisements>
I have stored the images that the
AdRotator control will use in the sample application in a folder named Images. (You can add a new folder to your project by right-clicking on the project name in Solution Explorer and then selecting New Folder from the context menu).
Figure 3 shows the Solution Explorer and the images I've used for this example.
When the
default.aspx page is loaded in a Web browser, you should see something similar to
Figure 4.

Figure 4. The Hyperlink and AdRotator controls are in use.
|
|

Figure 5. The ASPNetDB.mdb file is an Access database file located under the Data folder. |
Try clicking on the various
Hyperlink controls as well as the
AdRotator control. To see the different advertisements on the
AdRotator control, refresh the page a few times.
After a while, stop your project and examine your Solution Explorer (see
Figure 5). Refresh the Data folder (right-click on it and select Refresh Folder). You should see an Access database named ASPNetDB.mdb file located within this folder. By default, in Visual Studio Beta 1, the default Site Counters Provider uses an Access database to store the site statistics. You can change the provider to use a SQL Server via the
Web.config file.
 | |
| Figure 6. Examining the aspnet_SiteCounters table. |
Double-click on the
ASPNetDB.mdb file to open it (see
Figure 6). The
aspnet_SiteCounters table will display. If you look at the table carefully, you will notice that the first two rows represent the clicks made by the
Books Hyperlink control in the first two minute-intervals (3:59 PM to 4:00 PM and 4:00 PM to 4:01 PM). This corresponds to the value of 1440 set in the
RowsPerDay property as each row represents a minute.
The last row records the click made by the
AdRotator control. Because I used the default value of -1 for the
RowsPerDay property, you will notice that under the
StartTime and
EndTime fields, only the date is recorded and not the time. In this case, a row represents a single day.
Note that the Site Counters service will only register a click when the
AdRotator control is clicked. There are times where you might want to register a view every time the page containing the
AdRotator control is refreshed. In this case, you need to set the
CountViews property to True.