Search code examples
mongodbsitecoresitecore8sitecore-xdb

xDB not storing any Interactions


Update: So the issue was that my application Global.asax.cs did not derive from Sitecore.Web.Application.

So I have just installed Sitecore 8 with MongoDB 2.6.11.

For test purposes I placed the code below in page load event to activate the goal I have created earlier in sitecore.

The goal was created successfully via deploy and publish. I have also confirmed the item id of the goal is correct.

    if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.Current.CurrentPage != null)
    {
       Sitecore.Data.Items.Item GoaltoTrigger = Sitecore.Context.Database.GetItem("{EDA8EA2C-7AF5-4D0F-AF76-A9C4E6BD7169}");
       if (GoaltoTrigger != null)
       {
           Sitecore.Analytics.Data.Items.PageEventItem registerthegoal = new Sitecore.Analytics.Data.Items.PageEventItem(GoaltoTrigger);
           Sitecore.Analytics.Model.PageEventData eventData = Sitecore.Analytics.Tracker.Current.CurrentPage.Register(registerthegoal);
           eventData.Data = GoaltoTrigger["Description"];
           Sitecore.Analytics.Tracker.Current.Interaction.AcceptModifications();
       }
    }
    Session.Abandon();

Sadly this did not work and I can not see the goal in xDB under Interactions.

Other things I have looked into is that my layout definitely has the tag

<sc:VisitorIdentification runat="server" />

my Global.asax implements Sitecore.Web.Application

public class Global : Sitecore.Web.Application

Yet no luck. The Interactions are no where to be seen in Mongo (using mongo shell and roboMongo to look up the collection). Am I missing something else?

enter image description here

enter image description here

Sitecore Error

ManagedPoolThread #3 16:43:00 INFO  Job ended: Sitecore.ListManagement.Analytics.UnlockContactListsAgent (units processed: )
12980 16:43:05 INFO  Cache created: '[no name]' (max size: 976KB, running total: 2918MB)
12980 16:43:05 INFO  Cache created: '[no name]' (max size: 976KB, running total: 2919MB)
12980 16:43:05 INFO  Cache created: '[no name]' (max size: 976KB, running total: 2920MB)
12980 16:43:05 INFO  Cache created: '[no name]' (max size: 976KB, running total: 2921MB)
12980 16:43:05 INFO  Cache created: '[no name]' (max size: 976KB, running total: 2922MB)
ManagedPoolThread #5 16:43:06 ERROR Failed to perform MaxMind lookup
ManagedPoolThread #5 16:43:06 ERROR Failed to perform GeoIp lookup for 127.0.0.1
Exception: Sitecore.Analytics.Lookups.CannotParseResponseException
Message: Unexpected format. Cannot parse the MaxMind response for IP address: 127.0.0.1

Source: Sitecore.Analytics
   at Sitecore.Analytics.Lookups.MaxMindProvider.GetInformationByIp(String ip)
   at Sitecore.Analytics.Lookups.GeoIpManager.GetDataFromLookupProvider(GeoIpHandle geoIpHandle)

12980 16:43:08 INFO  Cache created: 'WebUtil.QueryStringCache' (max size: 19KB, running total: 2922MB)
2700 16:43:08 INFO  HttpModule is being initialized
12360 16:43:08 INFO  HttpModule is being initialized
7068 16:43:08 INFO  HttpModule is being initialized
9940 16:43:10 INFO  [Experience Analytics]: Reduce agent found zero segments to process
ManagedPoolThread #1 16:43:10 INFO  Job started: Sitecore.ListManagement.Analytics.UnlockContactListsAgent
ManagedPoolThread #1 16:43:10 INFO  Job ended: Sitecore.ListManagement.Analytics.UnlockContactListsAgent (units processed: )

Solution

  • Triggering goals

    First of all, this is the correct way to trigger a goal:

    if (Sitecore.Analytics.Tracker.IsActive)
    {
        if (Sitecore.Analytics.Tracker.Current.CurrentPage != null)
        {
            var goalId = new Sitecore.Data.ID("{EDA8EA2C-7AF5-4D0F-AF76-A9C4E6BD7169}");
    
            Sitecore.Analytics.Data.Items.PageEventItem goalToTrigger =
                Sitecore.Analytics.Tracker.DefinitionItems.PageEvents[goalId];
    
            if (goalToTrigger != null)
            {
                Sitecore.Analytics.Model.PageEventData eventData =
                    Sitecore.Analytics.Tracker.Current.CurrentPage.Register(goalToTrigger);
            }
            else
            {
                Sitecore.Diagnostics.Log.Error("Goal with ID " + goalId + " does not exist", this);
            }
        }
        else
        {
            Sitecore.Diagnostics.Log.Error("Tracker.Current.CurrentPage is null", this);
        }
    }
    else
    {
        Sitecore.Diagnostics.Log.Warn("The tracker is not active. Unable to register the goal.", this);
    }
    

    You should not attempt to change the event data after you've registered it.

    Also, you should not call Interaction.AcceptModifications(), as this method is something xDB uses internally at some point.

    CurrentPage.Register() is the only thing that you need to do.

    Ending the session

    I don't recommend using Session.Abandon(). It will probably result in saving your interaction to the collection database, but this way you are disrupting the normal flow of Sitecore's session. One of the problems that this may lead to is that the interaction's contact will remain locked for 21 minutes (or whatever your session timeout is set to + 1 minute).

    Instead, for testing purposes, I recommend you to set session timeout to 1 minute and just wait for 1 minute after your last page request. This setting is located in the Web.config as an attribute of <sessionState>.

    Troubleshooting interaction saving issues

    1. Make sure that the analytics connection string is set properly.
    2. Make sure that you have a license for xDB. You can see the list of available licenses in Sitecore Control Panel –> Administration –> Installed licenses.
      a) In Sitecore 8.0 or lower, the license name is Sitecore.OMS.
      b) In Sitecore 8.1 it's Sitecore.xDB.base.
    3. Make sure that xDB and its tracking subsystem are enabled.
      a) In Sitecore 8.0 or lower, Analytics.Enabled should be set to true in the Sitecore.Analytics.config.
      b) In Sitecore 8.1, both Xdb.Enabled and Xdb.Tracking.Enabled should be set to true in the Sitecore.Xdb.config.
    4. Tracking should also be enabled on site definitions.
      a) In Sitecore 8.0 or lower, go to the <sites> section in the Web.config and check that enableAnalytics is not set to false on <site name="website"> or whatever site you are using.
      b) In Sitecore 8.1, you should ensure that enableTracking is set to true for your site in the Sitecore.config.
    5. Try making several page requests instead of just one before letting the session to expire.
    6. Try disabling robot detection by setting both Analytics.Robots.IgnoreRobots and Analytics.AutoDetectBots to false in the Sitecore.Analytics.Tracking.config. If interactions are saved after this, I will update my answer with further instructions.
    7. If nothing helps, go through the steps listed in the article Troubleshooting xDB data issues.