---
title: Tracking campaigns on MVC sites
related:
  - https://docs.kentico.com/k11/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns.md
  - https://docs.kentico.com/k11/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns/setting-up-campaigns.md
  - https://docs.kentico.com/k11/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns/setting-up-campaigns/setting-up-campaigns-on-mvc-sites.md
  - https://docs.kentico.com/k11/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns/scheduling-and-evaluating-campaigns.md
  - https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc.md
  - https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/implementing-on-line-marketing-features-on-mvc-sites/tracking-campaigns-on-mvc-sites/customizing-the-page-visit-hash-function-for-campaigns-in-mvc.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:** **Kentico EMS required**
>
> Features described on this page require the **Kentico EMS** license.

You can use the on-line marketing [campaign tracking](https://docs.kentico.com/k11/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns.md) features with websites that are presented by a [separate MVC application](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc.md).

In this scenario, marketers define campaigns and measure their results in the interface of the Kentico application. However, the content targeted by the campaign is served on the MVC website, so developers need to take additional steps to ensure that the MVC site logs page visit conversions for campaigns.

## Registering campaign tracking on MVC sites

Perform the following steps to register campaign tracking functionality for your MVC application:

1. Open your MVC project in Visual Studio.
2. Install the following [integration packages](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/starting-with-mvc-development/installing-kentico-integration-packages.md) into your MVC project:

   - **Kentico.Activities**
   - **Kentico.Activities.Web.Mvc**
   - **Kentico.CampaignLogging.Web.Mvc**
3. Edit the application's **App\_Start/ApplicationConfig.cs** file.

   1. Add a _using_ statement for the **Kentico.CampaignLogging.Web.Mvc** namespace.

      ```csharp

      using Kentico.Web.Mvc;
      using Kentico.CampaignLogging.Web.Mvc;

      ```
   2. Call the predefined **UseCampaignLogger** method (from the _ApplicationBuilder_ instance in the **RegisterFeatures** method). This ensures that the application sends all actions through a campaign logger before they get to controllers.

      ```csharp

                  builder.UseCampaignLogger();


      ```
4. [Enable logging of all activity types for your MVC application](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/implementing-on-line-marketing-features-on-mvc-sites/logging-activities-on-mvc-sites/enabling-tracking-of-activities-on-mvc-sites.md) (both membership and page related activities).

When a visitor arrives on the MVC website through a campaign link with the required UTM parameters, the system can now log campaign page visits and other conversions.

## Adding MVC pages to campaigns

Adding pages to campaigns works differently if you only use Kentico as a content platform, with the website presented by a [separate MVC application](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc.md). In these scenarios where the Kentico site is "content only" (i.e., created using the _MVC Blank Site_ template), you cannot select pages from the content tree or create new pages from the campaign interface. MVC sites also do not display the published status of pages.

Moreover, adding the **Page visit** activity as a conversion or a campaign journey step works also differently for campaigns on MVC sites. See [Setting up campaigns on MVC sites](https://docs.kentico.com/k11/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns/setting-up-campaigns/setting-up-campaigns-on-mvc-sites.md) for more information.

> **Note:** **Important**: To track campaign page visits for content hosted on a separate MVC website, your site in Kentico must have its [Presentation URL](https://docs.kentico.com/k11/configuring-kentico/managing-sites/setting-domain-names-for-sites.md) set to the domain (and virtual directory) where the MVC site is running.

## Hashing of page visit activities

The system hashes the URLs of _Page visit_ conversions/journey steps and activities on MVC sites to be able to put data for reports together as quickly as possible.

By default, the hash function removes the protocol and all query strings from the URL. The campaign then works regardless of the used protocol (for example, for both _http_ and _https_). However, the default hash function does not work for sites where displaying of pages is performed via query strings or component identifiers (for example, if the URL of a page on your site looks like _http://www.mysite.com/index.html?viewpage=123_). More specifically, the noted address will be trimmed to _www.mysite.com/index.html_, and all pages trimmed to this "URL root" will be logged as conversions for one page. Therefore, [SEO-friendly URLs](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/providing-friendly-urls-on-mvc-sites.md) are recommended.

If your site displays its content using query strings or uses any uncovered scenarios, and you want to use campaigns, you can customize the hash function to fulfill your needs. To customize the default hash function, see [Customizing the page visit hash function for campaigns in MVC](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/implementing-on-line-marketing-features-on-mvc-sites/tracking-campaigns-on-mvc-sites/customizing-the-page-visit-hash-function-for-campaigns-in-mvc.md). On the referred page, there is also an example of a hash function that removes the culture code in the page URL so that the campaign works as expected on [multilingual MVC sites](https://docs.kentico.com/k11/multilingual-websites/setting-up-multilingual-websites.md).

> **Tip:** **Improving performance**
>
> To improve the performance of report calculation, create a database index on the **ActivityURLHash** column in the **OM\_Activity** database table. The index should be non-clustered and non-unique. See the [Create Nonclustered Indexes](https://msdn.microsoft.com/en-us/library/ms189280.aspx) article for more information.
