“Some” best practices I learned on commerce personalization

The concept of personalization is a wide range. I’m working on a project that needs personalization and started to learn. One cool thing I learn from “Foundation” project (Foundation is a very good sample of all Episerver offerings) is how to build a code to use Episerver Tracking Commerce. Again I’m learning and please advise me if I can improve any part of it ūüôā

Please read through how to install tracking Nuget package from here

The next step is to create a separate project in your solution and add a commerce tracking package to the solution. Then add a class as below:

public interface ICommerceTrackingService
    {
        Task<TrackingResponseData> TrackOrder(HttpContextBase httpContext, IPurchaseOrder order);
    }

    public class CommerceTrackingService: ICommerceTrackingService
    {
        private readonly IContextModeResolver contextModeResolver;
        private readonly TrackingDataFactory trackingDataFactory;
        private readonly ITrackingService trackingService;
        private readonly ServiceAccessor<IContentRouteHelper> contentRouteHelperAccessor;

        public CommerceTrackingService(IContextModeResolver contextModeResolver,
            TrackingDataFactory trackingDataFactory,
            ITrackingService trackingService,
            ServiceAccessor<IContentRouteHelper> contentRouteHelperAccessor)
        {
            this.contextModeResolver = contextModeResolver;
            this.trackingDataFactory = trackingDataFactory;
            this.trackingService = trackingService;
            this.contentRouteHelperAccessor = contentRouteHelperAccessor;
        }

        public async Task<TrackingResponseData> TrackOrder(HttpContextBase httpContext, IPurchaseOrder order)
        {
            if (contextModeResolver.CurrentMode != ContextMode.Default)
            {
                return null;
            }

            var trackingData = trackingDataFactory.CreateOrderTrackingData(order, httpContext);
            return await trackingService.TrackAsync(trackingData, httpContext, contentRouteHelperAccessor().Content);
        }
    }

I put both interface and class in the same file to simplify the post but if you want you can separate them.

Next step is to change you StructureMap to scan new project (this is optional depending on your StructureMap structure)

            context.StructureMap().Configure(config =>
            {
                config.Scan(scan =>
                {
                    scan.TheCallingAssembly();
                    scan.Assembly("EPiServer.Sample.Commerce.Personalization");
                    scan.WithDefaultConventions();
                    scan.LookForRegistries();
                });
            });

The next step is to call the track order. We want to do that when the order is being placed. So after cart converted to purchase order you can call your TrackOrder function:

commerceTrackingService.TrackOrder(httpContext, purchaseOrder);

This will push all relevant data from order to tracking engine to help the recommendation engine to get a better understanding of the user behavior.

I recommend to checkout “Foundation” project that has a very comprehensive sample.

Wrap Up – Third Sydney Episerver Meetup

First I want to say thanks @Nicola and 1990 Digital and Episerver for hosting this session. I learned a lot¬†and I’m started starving for the next meetup!

 

Nicola spoke about her new tool ‘EpiserverCmsAudit’. This tool is really awesome and can help you to find the usage of your content type. Very nice dashboard and very easy to install and it is FREE! So if you to give it a go to her post¬†to read more about it and you can take a look at the source code¬†or just install the Nuget package¬†This is quite a bit awesome while website moving to DXC as they can build many websites and many contents! So with this tool, you as a dev, tester or content editor can make sure your change impact on all aspect of your app! GREAT JOB!

 

I spoke about Episerver Headless CMS, eCommerce and how you can integrate that with Microsoft Web Bot. This would be important as Bots are more human-friendly Рhaving said that the concept is still at a very early stage. The concept is quite simple, Web Bot gets the query from user pass to Luis.ai and passes the action to Episerver to get the data back and pass it back to Bot! If you feel like you need more info, you can download the presentation and the source code of the bot can be found here and the bot source code can be found here. If you are interested and still have a question just comment here!

I’m going to speak about this in more detail in DDD, so if you keen to learn more you just need to get the ticket!

Episerver Developer Tool

Episerver is a great tool, especially for developers. Easy to learn and easy to adapt. One of the downfalls of any complex system is debugging. You need to have a good understanding of the architecture and have some domain knowledge about the area you are debugging. To speed up the process we usually rely on tools. Debugging Tools are very important part of the developer’s toolbox. Episerver has a¬†powerful tool which can help you to find issues and improve the application. It helps you to:

  • Container (IoC): Give you “StructureMap container used by EPiServer”
  • Content-Type Analyzer:¬†¬†content type Synchronization status during initialization
  • Loaded Assemblies
  • Log Viewer (In Memory Logs)
  • Memory Dump
  • Remote Event
  • Routes
  • Startup Performance
  • Templates
  • View Locations

To install this tool you can just install nuget package “EPiServer.DeveloperTools”. Just run powershell¬†script:

Install-Package EPiServer.DeveloperTools

And then when you build and run application and login to Episerver Admin area and you can see:

I personally use IoC container, Routes, View Location and Remote Event. Please remember Episerver is not actively supporting this tool and it is not recommended to use this tool in a production environment.

I would say, we are moving more to the cloud, we need more tools like this to help us debugging cloud-based services (e.g. Episerver Find).