0

I have Sitecore 8.2 installed in my local environment. I was investigating that is analytics/xDB working correctly in my setup. I opened my site with a browser and saved the cookie SC_ANALYTICS_GLOBAL_COOKIE value for myself and the browser a few pages. I waited that the session ends so that Sitecore flushed the data to MongoDB. I checked the interactions table in MongoDb and I can find the record where I visited the pages. What I noticed also is that the id of ContactId in that record does not match the one that I took from the cookie in the browser, although the Pages that were visited are correct. I did this a few times to make sure. Also, the Contacts table didn't have the same value.

Looking at the Sitecore documentation I understood that the cookie SC_ANALYTICS_GLOBAL_COOKIE value should be the same as ContactId. How come in my case it isn't?

1 Answer 1

0

You need to parse contact id from cookie value to Guid first and then convert it to ToBase64String.

Something like:

// Id of the Contact in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
string contactId = "50638e2f-43b2-46ee-806d-665f4fb08954";
    
var guid = Guid.Parse(contactId);
var bytes = guid.ToByteArray();

string encodedId = Convert.ToBase64String(bytes);

You will receive encodedId in a form similar to L45jULJD7kaAbWZfT7CJVA==.

Then you can query MongoDB using:

db.getCollection('Contacts').find({_id:new BinData(3, 'L45jULJD7kaAbWZfT7CJVA==')})

Code copied from and more details: https://jonathanrobbins.co.uk/2017/04/30/how-to-find-sitecore-contacts-in-xdb-mongodb/

1
  • thank you, now I can find the records from MongoDB Dec 9, 2020 at 8:31

Your Answer

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

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