---
title: Content personalization
related:
  - https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-contacts/setting-up-contact-tracking.md
  - https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/content-personalization/developing-personalization-condition-types.md
  - https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/personalizing-widgets.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.

Content personalization is an on-line marketing technique that creates pages with different content depending on the circumstances in which they are viewed. For example, you can build pages that offer special content for different types of visitors or dynamically change for each user according to the actions they performed on the website.

When [developing MVC websites](https://docs.kentico.com/13/developing-websites/mvc-development-overview.md), you can take two different approaches to create personalized content:

- [Allow marketers to personalize content added through page builder widgets](#setting-up-personalization-of-page-builder-widgets)
- [Write personalization conditions directly in the code of your MVC site's pages](#writing-personalization-conditions-in-mvc-code)

## Setting up personalization of page builder widgets

1. [Set up the page builder](https://docs.kentico.com/13/developing-websites/page-builder-development.md) for your MVC site.
2. Prepare some pages with [editable areas for the page builder](https://docs.kentico.com/13/developing-websites/page-builder-development/creating-pages-with-editable-areas.md).
3. Develop [widgets](https://docs.kentico.com/13/developing-websites/page-builder-development/developing-widgets.md) and [sections](https://docs.kentico.com/13/developing-websites/page-builder-development/developing-page-builder-sections.md) that allow your site's editors to add the required content.
4. Develop [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).
5. Enable content personalization in Xperience:
   1. Open the **Settings** application.
   2. Navigate to the **On-line marketing** settings category.
   3. Select the **Enable content personalization** checkbox.
   4. Click **Save**.

Marketers can now [personalize widgets](https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/personalizing-widgets.md) on pages where the page builder is enabled, using the condition types that you developed.

## Writing personalization conditions in MVC code

In addition to personalization of page builder widgets, you can write personalization conditions directly within the code of your MVC site's controllers, views or other classes. The conditions can leverage the visitor segmentation tools that marketers define within the Xperience application – [Contact groups](https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/segmenting-contacts-into-contact-groups.md) or [Personas](https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/personas.md).

> **Note:** **Prerequisite**
>
> You first need to set 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 before defining personalization conditions based on contact groups, personas or other contact properties.

> **Info:** **Note**: The **Settings -> On-line marketing -> Enable content personalization** setting does not have any effect on content personalization conditions written directly in code.

### Personalizing content based on contact groups

We recommend using [Contact groups](https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/contact-management/segmenting-contacts-into-contact-groups.md) to personalize your MVC site's content:

1. Define contact groups to segment your website's visitors (in the **Contact groups** application within Xperience).
2. Use the [contact tracking](https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-contacts/setting-up-contact-tracking.md) API to get the current contact in your MVC site's code.
3. Create conditions to display different content for contacts who belong to different contact groups.
4. Call one of the following extension methods for the current contact object within the conditions:

   - **IsInContactGroup** – evaluates whether the contact belongs to one specific contact group.
   - **IsInAnyContactGroup** – evaluates whether the contact belongs to _at least one_ of the specified contact groups.
   - **IsInAllContactGroups** – evaluates whether the contact belongs to _all_ of the specified contact groups.

     > **Info:** All of the methods return a boolean value that you can use in your content conditions.
     >
     > The methods accept one or more string parameters, which must match the **code names** of contact groups. To find the code names, edit contact groups in the _Contact groups_ application in Xperience.

The system segments your website's visitors into contact groups, for example according to [performed activities](https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-activities/enabling-activity-tracking.md). Your MVC site then displays personalized content depending on the contact groups to which the current visitor (contact) belongs.

```csharp title="Razor view example"

@using CMS.ContactManagement

@{
    // Gets the current contact
    ContactInfo currentContact = ContactManagementContext.GetCurrentContact();
}

@if (currentContact != null)
{
    // Displays personalized content for contacts belonging to the "YoungCustomers" contact group
    if (currentContact.IsInContactGroup("YoungCustomers"))
    {
        <text>Hiya @currentContact.ContactFirstName</text>
    }
    else
    {
        <text>Hello</text>
    }
}


```

### Personalizing content for personas

If you use [Personas](https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/personas.md) to segment your site's visitors, you can create conditions and serve different content for different personas.

To check whether a contact is assigned to a persona:

1. Get the contact's persona by calling the **GetPersona()** extension method for the contact object (requires a reference to the **CMS.Personas** namespace).
2. Create a condition that checks the code name of the persona (or any other persona property).

```csharp

using System;
using CMS.ContactManagement;
using CMS.Personas;


```

```csharp title="Example"

            // Gets the current contact
            ContactInfo currentContact = ContactManagementContext.GetCurrentContact();

            // Gets the code name of the current contact's persona
            string currentPersonaName = currentContact?.GetPersona()?.PersonaName;

            // Checks whether the current contact is assigned to the "EarlyAdopter" persona
            if (String.Equals(currentPersonaName, "EarlyAdopter", StringComparison.InvariantCultureIgnoreCase))
            {
                // Serve personalized content for the "EarlyAdopter" persona
            }


```

## Using output caching for personalized pages

When using [ASP.NET output caching](https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/improving-performance-with-output-caching-cs) to improve the performance of your MVC website, you need to take additional steps to ensure that the output cache correctly stores personalized pages. Because personalized pages serve different content based on various conditions, you need to adjust your application to cache separate output versions according to the personalization criteria.

See [Caching the output of personalized content](https://docs.kentico.com/13/configuring-xperience/configuring-caching/caching-the-output-of-personalized-content.md) for more information.

> **Info:** **Using client-side only output caching**
>
> An alternative approach that you can consider is to set the **Location** property of your **OutputCache** attributes to _**System.Web.UI.OutputCacheLocation.Client**_. This disables output caching on the server.
>
> With only client-side caching, each client device caches its own personalized content and you do not need to define custom cache variables. This scenario is easier to set up for heavily personalized pages, but the performance gains are usually lower than with optimally configured output caching for both the server and client sides.
