Logging activities

Enterprise license required

Features described on this page require the Kentico Xperience Enterprise license.

This page provides detailed instructions on logging of activities that require additional adjustments of your live site application.

Logging membership activities

To ensure that the system logs every performed Membership related activity, such as User registration and User login, you need to:

  1. Open your live site project in Visual Studio.

  2. Edit the code files that process sign-ins and registrations (MembershipController in the example code below).

  3. Initialize an instance of the IMembershipActivityLogger service.

    We recommend using a dependency injection container to initialize service instances.

    
    
    
     using CMS.Activities.Loggers;
     using CMS.Core;
    
    
     
    
    
    
         public class MembershipController : Controller
         {
             private readonly IMembershipActivityLogger membershipActivityLogger;
    
             public MembershipController(IMembershipActivityLogger membershipActivityLogger)
             {
                 this.membershipActivityLogger = membershipActivityLogger;
    
                 // ...
             }
    
             // ...
    
    
    
     
  4. Add code according to the activity types described below:

    • User registration activity – to log the user registration activity, call the LogRegistration method of the IMembershipActivityLogger instance. Specify the user name of the newly registered user as the method’s parameter.

      
      
      
                    membershipActivityLogger.LogRegistration(userName);
      
      
      
        
    • User login activity – to log the user login activity, call the LogLogin method of the IMembershipActivityLogger instance. Specify the user name of the signed in user as the method’s parameter.

      
      
      
                    membershipActivityLogger.LogLogin(userName);
      
      
      
        

The User registration activity will now be logged for every user that registers as a site member, and the User login activity will be logged for every user that signs into the site.

For logging of the External search and the Page related activities, you need to enable the activity tracking feature for your live site application.

  1. Open your MVC project in Visual Studio.

  2. Enable the activity tracking feature by calling the UseActivityTracking method of the ApplicationBuilder instance.

    • Enable the 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 Xperience MVC features).

      Note: The feature must be enabled before you register routes into the application’s RouteTable. The Kentico().MapRoutes() method adds required routes based on the set of enabled features.

      
      
      
        using Kentico.Activities.Web.Mvc;
        using Kentico.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 activity tracking feature
            builder.UseActivityTracking();
      
            ...
        }
      
      
        
  3. Register the activity logging script onto all pages by calling the ActivityLoggingScript extension method in views.

    • Call the method in your MVC website’s main layout (and any other used layouts) to ensure that performed activities are logged for every page.
    • The logging script runs asynchronously, so we recommend adding it at the end of the <head> tag in the page code.



@using Kentico.Activities.Web.Mvc





    @* Registers scripts that ensure logging of campaign page visits and page-related activities *@
    @Html.Kentico().ActivityLoggingScript()



  1. Open your live site project in Visual Studio.

  2. Edit your application’s startup class (Startup.cs by default).

  3. Enable the activity tracking feature by calling the UseActivityTracking method of the IFeaturesBuilder delegate passed to the IServiceCollection.AddKentico method within ConfigureServices.

    
    
    
     using Kentico.Activities.Web.Mvc;
     using Kentico.Web.Mvc;
    
     ...
    
     public void ConfigureServices(IServiceCollection services)
     {
         ...
         // Enables and configures Xperience features
         services.AddKentico(features =>
         {
             // Enables the activity tracking feature
             features.UseActivityTracking();
             ... 
         });
    
         ...
     }
    
    
     
  4. Register the activity logging script onto all pages by calling the ActivityLoggingScript extension method in views.

    • Call the method in your website’s main layout (and any other used layouts) to ensure that performed activities are logged for every page.

    • The logging script runs asynchronously, so we recommend adding it at the end of the <head> tag in the page code.

      
      
      
        @using Kentico.Activities.Web.Mvc
      
      
        
      
      
      
            @* Registers scripts that ensure logging of campaign page visits and page-related activities *@
            @Html.Kentico().ActivityLoggingScript()
      
      
      
        

Enabling the UseActivityTracking feature ensures that the system registers routes that receive activity logging requests.

After adding the code mentioned above, the Page visit activity is logged every time a page is visited, and the Landing page activity is logged every time a visitor opens a page when first viewing the website. Similarly, the External search activity is logged every time a site visitor uses an external search engine that leads them to the website.

Logging the Product added to wishlist activity

To ensure that your website logs the Product added to wishlist activity, you need to:

  1. Open your live site project in Visual Studio.

  2. Edit the code handling requests that add products to the wishlist (SampleWishlistController in the example code below).

  3. Initialize an instance of the IEcommerceActivityLogger service.

    We recommend using a dependency injection container to initialize service instances.

    
    
    
     using CMS.Core;
     using CMS.Ecommerce;
    
    
     
    
    
    
         public class SampleWishlistController : Controller
         {
             private readonly IEcommerceActivityLogger ecommerceActivityLogger;
    
             public SampleWishlistController(IEcommerceActivityLogger ecommerceActivityLogger)
             {
                 this.ecommerceActivityLogger = ecommerceActivityLogger;
    
                 // ...
             }
    
             // ...
    
    
    
     
  4. Call the LogProductAddedToWishlist method of the IEcommerceActivityLogger instance in the action that adds products to the wishlist. Specify the submitted product (SKUInfo) as the method’s parameter.

    
    
    
                 ecommerceActivityLogger.LogProductAddedToWishlistActivity(wishlistProduct);
    
    
    
     

The Product added to wishlist activity will now be logged when visitors add a product to their wishlist.

Logging the Internal search activity

To ensure that your website logs the Internal search activity, you need to:

  1. Open your live site project in Visual Studio.

  2. Edit the code thatprocesses search requests (SampleSearchController in the example code below).

  3. Initialize an instance of the IPagesActivityLogger service.

    We recommend using a dependency injection container to initialize service instances.

    
    
    
     using CMS.Core;
     using CMS.WebAnalytics;
    
    
     
    
    
    
         public class SampleSearchController : Controller
         {
             private readonly IPagesActivityLogger pagesActivityLogger;
    
             public SampleSearchController(IPagesActivityLogger pagesActivityLogger)
             {
                 this.pagesActivityLogger = pagesActivityLogger;
    
                 // ...
             }
    
             // ...
    
    
    
     
  4. Call the LogInternalSearch method of the IPagesActivityLogger instance in the action that handles search requests. Specify the submitted search keywords as the method’s parameter.

    
    
    
                 pagesActivityLogger.LogInternalSearch(searchKeywords);
    
    
    
     

The Internal search activity will now be logged when visitors use your website’s local search functionality.