---
title: Example - Developing a personalization condition type
related:
  - https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/content-personalization/developing-personalization-condition-types.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

> **Info:** **Enterprise license required**
>
> Features described on this page require the **Kentico Xperience Enterprise** license.

This page contains a full code sample that demonstrates how to develop a personalization condition type. To learn more about the development process in general, visit our [Developing personalization condition types](https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/content-personalization/developing-personalization-condition-types.md) page.

> **Note:** **Contact tracking**
>
> We recommend setting up [Tracking of contacts](https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-contacts/setting-up-contact-tracking.md) on your MVC website, as it is needed for the example to work correctly (and for most types of conditions that utilize Xperience on-line marketing features and data).

When finished, this condition type allows you to display different live site content to visitors based on [consent agreements](https://docs.kentico.com/13/configuring-xperience/data-protection/gdpr-compliance/creating-consents.md) they have given. Content editors are able to define different variants of widget content for any number of consents.

Create a **HasGivenConsentConditionType.cs** file in your MVC project's _\~/Personalization/ConditionTypes_ folder.

> **Note:** **Note**: The following example is based on the [LearningKit project](https://github.com/Kentico/LearningKit-Mvc). To use the code sample in your own project, you need to modify the namespaces, identifiers and other occurrences where _LearningKit_ is mentioned to match your project's name.

> **Tip:** We recommend using a [dependency injection container](https://docs.kentico.com/13/developing-websites/initializing-xperience-services-with-dependency-injection.md) to initialize service instances.

```csharp title="HasGivenConsentConditionType.cs"

using CMS.ContactManagement;
using CMS.Core;
using CMS.DataProtection;

using Kentico.Forms.Web.Mvc;
using Kentico.PageBuilder.Web.Mvc.Personalization;

using LearningKit.Personalization.ConditionTypes;

[assembly: RegisterPersonalizationConditionType("LearningKit.Personalization.HasGivenConsentConditionType",
    typeof(HasGivenConsentConditionType), "Has given consent agreement",
    Description = "Evaluates whether the contact has given an agreement with a specified consent declaration.",
    IconClass = "icon-clipboard-checklist",
    Hint = "Enter the code name of a consent. The condition is fulfilled for visitors who have given an agreement with the given consent.")]

namespace LearningKit.Personalization.ConditionTypes
{
    public class HasGivenConsentConditionType : ConditionType
    {
        // Parameter: Code name that identifies the consent for which visitors need to give an agreement to fulfill the condition
        // Assigns the default Xperience text input component to the property, which allows users to enter a text value in the configuration dialog
        [EditingComponent(TextInputComponent.IDENTIFIER, Order = 0, Label = "Consent code name")]        
        public string ConsentCodeName { get; set; }

        /// <summary>
        /// Default property representing the name of the personalization variant.
        /// </summary>
        public override string VariantName
        {
            get
            {
                // Uses the specified consent code name as the name of the variant
                return ConsentCodeName;
            }
            set
            {
                // No need to set the variant name property
            }
        }

        public override bool Evaluate()
        {
            // Gets the contact object of the current visitor
            ContactInfo currentContact = ContactManagementContext.GetCurrentContact(false);

            // Creates an instance of the consent agreement service
            // For real-world projects, we recommend using a dependency injection container to initialize service instances
            var consentAgreementService = Service.Resolve<IConsentAgreementService>();

            // Gets the consent object based on its code name
            ConsentInfo consent = ConsentInfo.Provider.Get(ConsentCodeName);
            if (consent == null || currentContact == null)
            {
                return false;
            }

            // Checks if the contact has given a consent agreement
            return consentAgreementService.IsAgreed(currentContact, consent);
        }
    }
}

```
