XConnect – Get a contact by their TrackerId…

So, Sitecore 9 has the replaced xDB in MongoDB with XConnect. Fine. Our contacts will be stored there (ultimately, in SQL server). Fine too.

One question though – how do we get the Sitecore.XConnect.Contact object for the current (possibly unidentified) contact?

It used to be that you could get the Contact record from Tracker.Current.Session.Contact, but that doesn’t work any more – that gets the Sitecore.Analytics.Tracking.Contact, which isn’t the same type at the Sitecore.XConnect.Contact which is replacing it. Confused yet?

Well, to make matters worse, the Sitecore.Analytics.Tracking.Contact.ContactId may or may not match the Sitecore.XConnect.Contact.ContactId. I think.

I couldn’t find any information about how to resolve the Tracker ID to the XConnect contact. What’s a boy to do?

EDIT: Sadly, there is a better way than below. Unfortunately, it’s in a different bit of the documentation. See https://doc.sitecore.net/developers/xp/tracking-and-session/tracker/tracking-contacts/contact-facets/update-facets.html

Continue reading “XConnect – Get a contact by their TrackerId…”

XConnect – Get a contact by their TrackerId…

Clearing Sitecore Analytics data

So I’ve been moving a Sitecore website to a live server, and one of the problems I had was that the analytics database already had data in it. The MongoDB instance was new, so that was empty – but how do I clear our test/development data out of the Analytics database?

Well it turns out that there is a stored procedure – __DeleteAllReportingData – in the Analytics database for just that:


Run that, and all your data will be gone. Obviously, use with care – but useful.

It seems to work by removing all foreign keys, truncating each table, and adding the keys back, so the user running this will need permission to do all these things.

Also, you can exclude tables, but I just ran it with the input of an empty string ( ” ) to clear all.

Clearing Sitecore Analytics data