Share via


How to Display House Ads versus Paid Ads

The display of house ads versus paid ads is governed by the What Is the Content Selection Pipeline?. House ads are displayed when the paid ad threshold is reached.

The Content Selection pipeline is influenced by user-configurable exposure limit, weight, page groups, and targeting expression variables. You can programmatically adjust these variables by using the Marketing classes to influence the weighting of paid versus house ads, whenever necessary.

To modify an advertisement

  1. Use the CampaignItemManager object (MarketingContext.CampaignItems) to retrieve the ad by ID.

  2. You can then set ExposureLimit to change the exposure limit.

  3. HouseAdWeight sets the weight (only applicable for house ads).

  4. Page groups and targeting information are collections stored in PageGroups andTargets, respectively.

Example

This example works with an existing house ad named "House Ad #1". It adjusts ExposureLimit and HouseAdWeight properties, and adds a PageGroup and expression target.

Make sure that the following references are included for this example:

using System.Security.Principal;
using System.Threading;
using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Runtime;
using Microsoft.CommerceServer.Marketing;

// This code requires you to add the following references:
// Microsoft.CommerceServer.CrossTierTypes
// Microsoft.CommerceServer.Marketing.CrossTierTypes
// Make sure that your user account has sufficient Marketing
// permissions to perform these operations.

// Get credentials needed by MarketingContext.Create().
IPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
Thread.CurrentPrincipal = principal;
string currentUser = principal.Identity.Name;

// Create a new MarketingContext using credentials.
MarketingContext marketingSystem = MarketingContext.Create("https://localhost/MarketingWebService/MarketingWebService.asmx");

// Look up an existing house ad.
SearchClauseFactory adsearchClauseFactory = marketingSystem.CampaignItems.GetSearchClauseFactory();
SearchClause adsc = adsearchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "Name", "House Ad #1");
DataSet addataSet = marketingSystem.CampaignItems.Search(adsc);
int adId = (int)addataSet.Tables["SearchResults"].Rows[0][0];

// Retrieve the ad.
CampaignItem ci = marketingSystem.CampaignItems.GetCampaignItem(adId);

// If the ad is active then it must be deactivated before adding the expression target.
if (ci.Active)
    marketingSystem.CampaignItems.Deactivate(adId);
            
// Convert the CampaignItem to a DisplayableCampaignItem.
DisplayableCampaignItem dci = (DisplayableCampaignItem)ci;

// Adjust the ad exposure limit.
dci.ExposureLimit = 5;

// Retrieve a Marketing page group.
int pageGroupId = 3;
PageGroup pg = marketingSystem.PageGroups.GetPageGroup(pageGroupId);

// Clear the ad page group collection (for this example).
dci.PageGroups.Clear();
dci.Save(false);

// Add the page group to the ad.
dci.PageGroups.Add(pg);
             
// Look up an existing targeting expression.
SearchClauseFactory exSearchClauseFactory = marketingSystem.Expressions.GetSearchClauseFactory();
SearchClause exsc = exSearchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "Name", "newTargetExpression");
DataSet exdataSet = marketingSystem.Expressions.Search(exsc);
int expressionId = (int)exdataSet.Tables["SearchResults"].Rows[0][0];

// Retrieve the expression.
Expression ex = marketingSystem.Expressions.GetExpression(expressionId);

// Map to an expression target.
ExpressionRef expRef = marketingSystem.Expressions.NewExpressionRef(expressionId);
TargetAction action = TargetAction.Target;
ExpressionTarget target = new ExpressionTarget(expRef, action);

// Add the expression target to the ad.
dci.Targets.Add(target);

// Save the ad changes.
dci.Save(false);

// Adjust the house ad weight
Advertisement adv = (Advertisement)ci;
adv.HouseAdWeight = 3;
adv.Save(false);

See Also

Other Resources

What Is the Content Selection Pipeline?