AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    Administration interface basicsDevelopers and adminsBusiness usersChangelogGlossary
  • Guides
    Welcome to Xperience by KenticoAdministration interface basicsCustomer journeysDigital marketingConfigurationDevelopmentArchitectureUpgrade to Xperience by Kentico
  • Training
    For AdminsFor Business usersFor DevelopersFor Solution architects
  • API Examples
    ConfigurationContent managementDevelopmentDigital marketing
  • Changelog
    Documentation updatesSecurity advisories
  1. Home
  2. Digital marketing
  3. Campaigns

Campaigns


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Dependency injection
    • Initialize required services
  • Campaigns
    • Create a campaign
    • Update a campaign
    • Update multiple campaigns
    • Delete a campaign
  • Campaign assets
    • Assign a content item to a campaign
    • Assign a form to a campaign
    • Assign a page to a campaign
    • Remove a campaign asset reference

Dependency injection

Initialize required services

C#
// Initializes all services and provider classes used within
// the API examples on this page using dependency injection.
private readonly IInfoProvider<CampaignInfo> campaignInfoProvider;
private readonly IInfoProvider<CampaignReferenceInfo> campaignReferenceInfoProvider;
private readonly IContentQueryExecutor contentQueryExecutor;
private readonly IInfoProvider<BizFormInfo> bizFormInfoProvider;


public CampaignsServices(IInfoProvider<CampaignInfo> campaignInfoProvider,
                         IInfoProvider<CampaignReferenceInfo> campaignReferenceInfoProvider,
                         IContentQueryExecutor contentQueryExecutor,
                         IInfoProvider<BizFormInfo> bizFormInfoProvider)
{
    this.campaignInfoProvider = campaignInfoProvider;
    this.campaignReferenceInfoProvider = campaignReferenceInfoProvider;
    this.contentQueryExecutor = contentQueryExecutor;
    this.bizFormInfoProvider = bizFormInfoProvider;
}
> Back to list of examples

Campaigns

Create a campaign

C#
// Creates a new campaign object
CampaignInfo newCampaign = new CampaignInfo()
{
    CampaignDisplayName = "Summer sale",
    CampaignName = "SummerSale",
    CampaignBrief = "A campaign promoting summer discounts.",
    CampaignStartWhen = new DateTime(2026, 6, 1),
    CampaignEndWhen = new DateTime(2026, 8, 31)
};

// Saves the campaign to the database
// The customer journey for the campaign is automatically created and linked
campaignInfoProvider.Set(newCampaign);
> Back to list of examples

Update a campaign

C#
// Gets the campaign by its code name
CampaignInfo updateCampaign = campaignInfoProvider.Get("SummerSale");

if (updateCampaign != null)
{
    // Updates the campaign's properties
    updateCampaign.CampaignDisplayName = "Summer sale 2026";
    updateCampaign.CampaignBrief = "Updated brief for the summer sale campaign.";

    // Saves the modified campaign to the database
    campaignInfoProvider.Set(updateCampaign);
}
> Back to list of examples

Update multiple campaigns

C#
// Gets all campaigns with a code name that starts with 'Summer'
var campaigns = campaignInfoProvider.Get().WhereStartsWith("CampaignName", "Summer");

// Loops through individual campaigns
foreach (CampaignInfo campaign in campaigns)
{
    // Updates the campaign properties
    campaign.CampaignDisplayName = campaign.CampaignDisplayName.ToUpper();

    // Saves the modified campaign to the database
    campaignInfoProvider.Set(campaign);
}
> Back to list of examples

Delete a campaign

C#
// Gets the campaign by its code name
CampaignInfo deleteCampaign = campaignInfoProvider.Get("SummerSale");

if (deleteCampaign != null)
{
    // Deletes the campaign
    campaignInfoProvider.Delete(deleteCampaign);
}
> Back to list of examples

Campaign assets

Assign a content item to a campaign

C#
// Gets the campaign
CampaignInfo campaign = campaignInfoProvider.Get("SummerSale");

if (campaign != null)
{
    // Gets the content item ID using the content item query API
    string CONTENT_TYPE = "Acme.Article";
    ContentItemQueryBuilder builder =
            new ContentItemQueryBuilder()
                    .ForContentType(CONTENT_TYPE, q =>
                    {
                        q.TopN(1)
                            .Where(w => w.WhereEquals("ArticleName", "Summer sale"));
                    });

    var itemIds = await contentQueryExecutor.GetResult<int>(builder, rowData =>
    {
        return rowData.ContentItemID;
    },
    // Retrieves the latest version of items
    new ContentQueryExecutionOptions() { ForPreview = true });

    int contentItemId = itemIds.FirstOrDefault();

    if (contentItemId > 0)
    {
        // Creates a new campaign reference object linking a content item to the campaign
        CampaignReferenceInfo newReference = new CampaignReferenceInfo()
        {
            CampaignReferenceCampaignID = campaign.CampaignID,

            // Sets the ID of the content item to associate with the campaign
            CampaignReferenceContentItemID = contentItemId
        };

        // Saves the campaign reference to the database
        campaignReferenceInfoProvider.Set(newReference);
    }
}
> Back to list of examples

Assign a form to a campaign

C#
// Gets the campaign
CampaignInfo campaign = campaignInfoProvider.Get("SummerSale");

// Gets the form by its code name
BizFormInfo form = bizFormInfoProvider.Get("ContactUs");

if (campaign != null && form != null)
{
    // Creates a new campaign reference object linking a form to the campaign
    CampaignReferenceInfo newReference = new CampaignReferenceInfo()
    {
        CampaignReferenceCampaignID = campaign.CampaignID,

        // Sets the ID of the form to associate with the campaign
        CampaignReferenceFormID = form.FormID
    };

    // Saves the campaign reference to the database
    campaignReferenceInfoProvider.Set(newReference);
}
> Back to list of examples

Assign a page to a campaign

C#
// Gets the campaign
CampaignInfo campaign = campaignInfoProvider.Get("SummerSale");

if (campaign != null)
{
    // Gets the web page item ID using the content item query API
    string PAGE_CONTENT_TYPE = "Acme.LandingPage";
    ContentItemQueryBuilder builder =
            new ContentItemQueryBuilder()
                    .ForContentType(PAGE_CONTENT_TYPE, q =>
                    {
                        q.ForWebsite("AcmeWebsite")
                         .TopN(1)
                         .Where(w => w.WhereEquals("LandingPageTitle", "Summer sale"));
                    });

    var pageIds = await contentQueryExecutor.GetWebPageResult<int>(builder, rowData =>
    {
        return rowData.WebPageItemID;
    },
    // Retrieves the latest version of items
    new ContentQueryExecutionOptions() { ForPreview = true });

    int webPageItemId = pageIds.FirstOrDefault();

    if (webPageItemId > 0)
    {
        // Creates a new campaign reference object linking a page to the campaign
        CampaignReferenceInfo newReference = new CampaignReferenceInfo()
        {
            CampaignReferenceCampaignID = campaign.CampaignID,

            // Sets the ID of the web page item to associate with the campaign
            CampaignReferenceWebPageItemID = webPageItemId
        };

        // Saves the campaign reference to the database
        campaignReferenceInfoProvider.Set(newReference);
    }
}
> Back to list of examples

Remove a campaign asset reference

C#
// Gets the campaign
CampaignInfo campaign = campaignInfoProvider.Get("SummerSale");

if (campaign != null)
{
    // Gets all asset references for the given campaign
    var references = campaignReferenceInfoProvider.Get()
        .WhereEquals("CampaignReferenceCampaignID", campaign.CampaignID);

    // Loops through the references
    foreach (CampaignReferenceInfo reference in references)
    {
        // Deletes the campaign reference
        campaignReferenceInfoProvider.Delete(reference);
    }
}
> Back to list of examples