On a Sitecore 9.1 project recently I ran into an issue relating to Federated Experience Manager due to a hidden and undocumented configuration usage.
In the project I was working on the environment was set up for multisite, and when I put the FXM javascript token on an owned, but non-sitecore site, the instance started erroring on all transactions and was completely failing at tracking users on the external site (the whole point of FXM).
Looking into the error logs I was receiving the following error:
2019-03-06T18:10:46 PID[20904] Error 21720 18:10:46 ERROR [FXM Tracking] [Error] : [TrackPageVisit] : Page = https://www.mysite.com/ : Referrer = https://www.mysite.com/ : CID = 307a8e720ff042d6b6fc5af7704a4198|True Exception: System.NullReferenceException Message: Object reference not set to an instance of an object. Source: Sitecore.FXM at Sitecore.FXM.Utilities.FxmUtility.GetWebDatabaseName(BaseSiteManager siteManager, BaseSettings settings) at Sitecore.FXM.Pipelines.Tracking.InitializeContext.InitializeContextSiteProcessor.ResolveSiteContext(IDomainMatcher domainMatcher) at Sitecore.FXM.Pipelines.Tracking.InitializeContext.InitializeContextSiteProcessor.Process(TrackingInitializeContextArgs args) at (Object , Object ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) at Sitecore.FXM.Pipelines.Tracking.TrackPageVisit.RunInitializeTrackingContextProcessor.Process(ITrackPageVisitArgs args) at (Object , Object[] ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) at Sitecore.FXM.Tracking.TrackingManager.<>c__DisplayClass6_0.<TrackPageVisit>b__0(FxmRequestContext fxmContext, TrackingResult result) at Sitecore.FXM.Tracking.TrackingManager.GenericServeTrackingRequest(SpoofedHttpRequestBase spoofedRequest, String contactId, Action`2 implementation) at Sitecore.FXM.Service.Controllers.BeaconController.<>c__DisplayClass10_0.<TrackPageVisit>b__0() at Sitecore.FXM.Service.Controllers.BeaconController.ExecuteTrackingRequest(String requestInfo, Func`1 implementation)
What I found out (with the help of Sitecore Support), is that FXM uses the configuration setting “Preview.DefaultSite” to determine what website is its default.
<setting name=”Preview.DefaultSite” value=”website” />
This is not documented by Sitecore, and seems like an oversight from development. In my multi-site application, I removed the “website” site configuration, so a null reference was created on the default site for preview. Updating Preview.DefaultSite to any of the sites defined in the configurations caused FXM to begin working as expected.
A very small change to correct what was a game breaking bug.