8

I have a requirement to identify the returning user which haven't yet created their profile. I know that Sitecore gives the unique identifier to the anonymous user based on the device and stores the information in the cookie.

But when I am trying to get the interactions data from the xConnect API using below code:

var session = Sitecore.Analytics.Tracker.Current.Session.Interaction

I am only getting the pages from the current visit of the user. Even though I am using the same device and same browser.

How do I get all the previous sessions that visitor has browsed assuming they haven't cleared their browser cookies.

1 Answer 1

1

You can use ContactRepository to load previous interactions:

ContactRepository contactRepository = Factory.CreateObject("tracking/contactRepository", true) as ContactRepository;//or new ContactRepository();
IEnumerable<IInteractionData> lastInteraction = contactRepository.LoadHistoricalInteractions(contactid, visitsToLoad, pastDateTime, currentDateTime);

Where:

  • visitsToLoad - amount of visits that you are interested in.(Could be int.MaxValue)
  • pastDateTime - from what date filter, could be null
  • currentDateTime - to what date filter, could be null
4
  • I am getting the below error on the first line Could not find configuration node: tracking/contactRepository. I had a look into the configuration I can see <tracking> <contactManager type="Sitecore.Analytics.Tracking.ContactManager, Sitecore.Analytics" singleInstance="true" patch:source="Sitecore.Analytics.Tracking.Database.config">...</contactManager> I am not sure why it is not able to find it.
    – Arun Kumar
    Feb 3, 2018 at 14:19
  • Also my xDB index in solr has nothing in it. It doesn't have any documents.
    – Arun Kumar
    Feb 3, 2018 at 14:42
  • can you try new ContactRepository() instead of Factory.CreateObject("tracking/contactRepository", true) as ContactRepository; ?
    – Anton
    Feb 3, 2018 at 16:52
  • It seems to give me the historical interactions. Thanks for the help :)
    – Arun Kumar
    Feb 5, 2018 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.