---
title: Enabling campaign tracking
related:
  - https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns.md
  - https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns/setting-up-campaigns.md
  - https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns/scheduling-and-evaluating-campaigns.md
  - https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/enabling-campaign-tracking/customizing-the-page-visit-hash-function-for-campaigns.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.

Marketers define [campaigns](https://docs.kentico.com/13/on-line-marketing-features/managing-your-on-line-marketing-features/campaigns.md) and measure their results in the interface of the Xperience administration application. However, the content targeted by the campaign is served by the separate live site application ([MVC 5](https://docs.kentico.com/13/developing-websites/mvc-development-overview.md) or [Core](https://docs.kentico.com/13/developing-websites/developing-xperience-applications-using-asp-net-core.md)), so developers need to take additional steps to ensure that the site logs page visit conversions for campaigns.

## Registering campaign tracking

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

<!-- dev-model:mvc start -->

**MVC 5 development model.** Applies only when building with ASP.NET MVC 5. If this page also covers ASP.NET Core, that version is in its own block.

1. Open your MVC project in Visual Studio.
2. Call the **UseCampaignLogger** method of the _ApplicationBuilder_ instance.

   - Enable the campaign logging feature at the start of your application's life cycle, for example in the **Application\_Start** method of your project's **Global.asax** file.

     > **Info:** MVC projects created by the [installer](https://docs.kentico.com/13/installation/installing-xperience.md) contain the _ApplicationConfig_ class, whose _RegisterFeatures_ method is called in the _Application\_Start_ method by default. You can use this class to encapsulate all of your _ApplicationBuilder_ code (enabling and configuring of Xperience MVC features).

     ```csharp

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

     ...

     protected void Application_Start()
     {
         ...

         // Gets the ApplicationBuilder instance
         // Allows you to enable and configure selected Xperience MVC integration features
         ApplicationBuilder builder = ApplicationBuilder.Current;

         // Enables the campaign logging feature
         builder.UseCampaignLogger();

         ...
     }

     ```

     > **Info:** The **UseCampaignLogger** method ensures that the application sends all actions through a campaign logger before they get to controllers.
3. [Enable logging of all activity types for your application](https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-activities/enabling-activity-tracking/logging-activities.md) (both membership and page-related activities).

<!-- dev-model:mvc end -->

<!-- dev-model:core start -->

**ASP.NET Core development model.** Applies only when building with ASP.NET Core. If this page also covers MVC 5, that version is in its own block.

1. Open your live site project in Visual Studio.
2. Edit your application's startup class (**Startup.cs** by default).
3. [Enable](https://docs.kentico.com/13/developing-websites/developing-xperience-applications-using-asp-net-core/starting-with-asp-net-core-development/enabling-xperience-features-in-asp-net-core-applications.md) the web analytics feature by calling the **UseCampaignLogger** method of the _IFeaturesBuilder_ delegate passed to the _IServiceCollection.AddKentico_ method within _ConfigureServices_.

   ```csharp

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

   ...

   public void ConfigureServices(IServiceCollection services)
   {
       ...
       // Enables and configures Xperience features
       services.AddKentico(features =>
       {
           // Enables the campaign logging feature
           features.UseCampaignLogger();
           ... 
       });

       ...
   }

   ```
4. [Enable logging of all activity types for your application](https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-activities/enabling-activity-tracking/logging-activities.md) (both membership and page-related activities).

<!-- dev-model:core end -->

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

## Hashing of page visit activities

The system hashes the URLs of _Page visit_ conversions/journey steps and activities 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, we recommend using [URLs](https://docs.kentico.com/13/developing-websites/implementing-routing/custom-routing-using-url-patterns.md) without query string parameters.

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](https://docs.kentico.com/13/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/enabling-campaign-tracking/customizing-the-page-visit-hash-function-for-campaigns.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 sites](https://docs.kentico.com/13/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://docs.microsoft.com/en-us/sql/relational-databases/indexes/create-nonclustered-indexes?view=sql-server-2017) article for more information.
