Content Selection Programming Concepts

The ContentSelector object is used to invoke Content Selection Framework (CSF) pipelines to display dynamic, targeted content on a Web page. The ContentSelector object is a property bag that inherits the properties and methods of the Dictionary object and adds the GetContent method. The dictionary object passed to the GetContent method, the global Context dictionary for the CSF application, is used to pass global objects and other values to the pipeline. These values include the location of the redirector script (Redir.asp), the expression evaluator object, and the Content Selection pipeline that should be run to select the content. These values do not change on a per-request basis.

Certain pipeline components in the CSF pipeline expect certain values, some optional, to be set in the dictionary. For example, the CSF pipeline expects the Size, PageGroups, NumRequested, and UserProfile keys to be set in the dictionary.

Redirecting Users

To capture and record the final click events before users navigate away from your site Commerce Server 2000 includes the redirector script, Redir.asp. For example, if an advertiser on your site supplies you with an ad and requests that when the ad is clicked the browser should navigate to the advertiser's site, then without a mechanism such as the redirector, Commerce Server 2000 will have no way to know that the user clicked on the ad. Being able to track these final click events enables you to analyze the performance and success of targeted content on your Web site.

To implement the Redir.asp script you must create an Event Processing pipeline in the Global.asa file. The following code creates the Event Processing pipeline and can be added to the code in the Code to Support the ContentSelection Object topic.

Dim dCSFAdsContext
Set oPipe = Server.CreateObject ("Commerce.OrderPipeline")
oPipe.LoadPipe (oPipelineMap.RecordEvent)
Set Application ("CampaignsCSFEventPipe") = oPipe

The following code should be included in the Redir.asp script.

Ee796511.note(en-US,CS.10).gif Note

  • The Solution Sites and the Advertising Sitelet include versions of the Redir.asp script that you can reuse.
Sub Main()
    Dim oPipe, sUrl, sCacheName, oContentList
    Dim dictCache, dictOrder, dictContext
    Dim Errlvl, oFactory, ciid, sEvt

    ' Get Pipeline object.
    Set oPipe = Application("CampaignsCSFEventPipe")

    ' Get the Content cache that this event is associated with.
    sCacheName = Request.Querystring("CacheName")

    If sCacheName <> "" Then
    ' Get cache object
    Set dictCache = Application("MSCSCacheManager").GetCache(sCacheName)

        ' Get name of event to record (default is CLICK).
        sEvt = Request.Querystring("evt")
        If sEvt = "" Then sEvt = "CLICK"

        ' Set up Order and Context dictionaries and execute the pipeline.
        If ciid > 0 Then
            ' Create dictionaries
            Set dictOrder = Server.CreateObject("Commerce.Dictionary")
            Set dictContext = Server.CreateObject("Commerce.Dictionary")

            ' "_winners" is the item(s) to record the event for.
            ' (may be a simplelist or a scalar)
            dictOrder("_winners") = ciid

            ' "_event" is the name of the event to record. You cannot
            ' record more than one event name per pipeline invocation.
            dictOrder("_event") = sEvt

            ' Create a content list of items from the given cache.
            Set oFactory = dictCache("Factory")
            Set oContentList = oFactory.CreateNewContentList
            Set dictOrder("_content") = oContentList

            ' Get the in-memory dictionary of campaign item performance.
            Set dictOrder("_Performance") = dictCache("_Performance")
            dictContext("SiteName") = sCacheName

            ' Look up page group ID.
            If Request.QueryString("PageGroupId") <> "" Then
                dictContext("PageGroupId") = 
                CLng(Request.QueryString("PageGroupId"))
            Else
                dictContext("PageGroupId") = 0
            End If

            ' Execute the pipeline to record the event.
            oPipe.orderExecute 1, dictOrder, dictContext, Errlvl

        End If
    End If

    ' Redirect to the supplied URL.
    sUrl = Request.Querystring("url")
    If sUrl <> "" Then 
        Response.Redirect(sUrl)
    Else 

        Response.Write(MSCSMessageManager.GetMessage
        ("L_NoRedirectionURLSpecified_ErrorMessage", sLanguage))
    End if
End Sub

Advertising Sitelet

Included with Commerce Server 2000 Software Development Kit (SDK) is the Advertising Sitelet. The Advertising Sitelet is an example of how ContentSelector objects can be implemented to show targeted content based on the profile of the user.

For more information about unpacking the Advertising Sitelet, see Adding a Site. The file to unpack, SDK-AD-SITELET.PUP, is located in the C:\Program Files\Microsoft Commerce Server\SDK\Samples\Sitelets\Ad directory on your local computer.


All rights reserved.