Tracking campaigns on MVC sites

Kentico EMS required

Features described on this page require the Kentico EMS license.

You can use the on-line marketing campaign tracking features with websites that are presented by a separate MVC application.

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. 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.

      MVC projects created by the installer 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 Kentico MVC features).

        using Kentico.Web.Mvc;
        using Kentico.CampaignLogging.Web.Mvc;
        protected void Application_Start()
            // Gets the ApplicationBuilder instance
            // Allows you to enable and configure selected Kentico MVC integration features
            ApplicationBuilder builder = ApplicationBuilder.Current;
            // Enables the campaign logging feature

      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 MVC application (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 now logs campaign page visits and other conversions.

Adding MVC pages to campaigns

Adding pages to campaigns works differently if you use Kentico as a content platform, with the website presented by a separate MVC application. In these scenarios where the Kentico site is “content-only”, 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 differently for campaigns on MVC sites. See Setting up campaigns on MVC sites for more information.

Important: To track campaign page visits for content hosted on an MVC website, your site in Kentico must have its Presentation URL 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 More specifically, the noted address will be trimmed to, and all pages trimmed to this “URL root” will be logged as conversions for one page. Therefore, we recommend using URLs 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 in MVC. 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.

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 article for more information.