<% Set objAd = Application("MyAd") %>
Next you need to decide where on your page you want the ad to appear, and insert the necessary lines of code at the appropriate spot. To make a request for an ad to Ad Server we simply use the 'GetAd' method. So the following line of code is all you need to get an ad to appear on your page:
<% Response.Write (objAd.GetAd) %>
If you look at the source of the page returned to the client, you will see that AdServer has inserted all the HTML code necessary to display an ad. It should look something similar to the following:
<a href="adredir.asp?ciid=9&url=http://www.thiscompany.com/" target="_top"> <img src="/GuruWeb/ads/thiscompany.gif" width=468 height=60 border="1" alt="This Company"></A>
To better understand what is going on we shall briefly detail where AdServer obtains the various values you see in the HTML code. Firstly the 'href' of the A tag is the value assigned to the AdServer 'RedirectURL' property in the global.asa file. The 'ciid' of the query string is a unique id automatically assigned to each 'campaign item' by AdServer. (Click on any campaign item in Ad Manager, and on the left-hand side under Campaign Item Properties, this is the first property listed.) All the other values are obtained from the database used by AdManager, and represent the values entered by you when you added that particular campaign item. (The dimensions of the image are the default ones associated with each ad size.)
Now as we intend to produce reports on advertising activity, we need to record the relevant information in the IIS log files, and the way to do this is with the 'Response' parameter of the GetAd method. This is the ASP intrinsic Response object. So the line of code should now read:
<% Response.Write (objAd.GetAd(Response)) %>
This is the simplest way of displaying ads, and Ad Server will select any active campaign item for that slot according its schedules. However, if you want to target certain types of ad for a particular slot, you'll need to use tags.
The TagList Parameter As was mentioned earlier, you can create whatever tags you like to specify information about the page. You cannot, however, create tags that begin with 'ad.' as these are reserved by Ad Server. These reserved tags are:
<% arrTags = Array("ad.size.banner", "ad.border.0", "subject.xml") Response.Write (objAd.GetAd (Response, arrTags, null)) %>
The reserved 'ad.size' tag means that only those ads that match that size will be considered for selection. Any custom tags will further influence the selection depending on the tags associated with individual campaign items, and their accompanying action (see the section on Ad Manager). You may have noticed a third parameter, null, being passed to the GetAd method; this is the HistoryString, which we come to next.
The HistoryString Parameter You can limit the number of times a visitor sees any particular ad during a session in two ways: setting the exposure limit in Ad Manager, and using the HistoryString parameter of the GetAd method. The HistoryString is a comma-delimited string of the ID's of those ads which have already been delivered to a user during the current session. This string is passed to Ad Server when a request for an ad is made, and is taken into consideration when selecting an ad to deliver. When an ad is delivered, the HistoryString is passed back with the ID of the current ad appended to it. To make use of this feature you need to add two lines of code, and pass the HistoryString as the third argument to the GetAd method:
<% arrTags = Array("ad.size.banner", "ad.border.0", "subject.xml") strHistory = Session("AdHistory") Response.Write (objAd.GetAd (Response, arrTags, strHistory)) Session("AdHistory") = strHistory %>
And that's it. You now know enough to set up new customers in Ad Manager, create advertising campaigns for them, and include adverts in those campaigns. You can also add the code to those pages where you want ads to appear. With Ad Manager you can fully control all advertising activity on your site, and monitor performance. All that remains now is to produce reports, and that is the subject of the next three pages.