In last couple of weeks I was working to resolve XDB issue in a Sitecore implementation (V8.2).
For one of my analysis I was supposed to verify if all the anonymous contacts and their corresponding page visits are tracked in MongoDB.
After lot of findings and querying against MongoDBcollections came across excellent blog from jonathanrobbins which helped me to figure out the contacts in MongoDB and then I went ahead to query all the corresponding user visits.
Below is the summary of my findings which I would like to document so that its a handy documentation helpful for others and for me too if i want to query MongoDB for similiar verification.
- Sitecore relies on cookies to track anonymous contacts – cookie name:SC_ANALYTICS_GLOBAL_COOKIE
- Sample sc_analytics value : “43dd8a5d41c347cbb2bb0255da48d783|True”
- cookie value contains Guid which is ContactId and a bool with a pipe identifier.
- bool value is set by Sitecore as – IsClassificationGuessed (true or false)
- for a new visitor its set to false(as can be human or robot). When visitor classification is determined , its set to true and now contact information can be pushed to MongoDB.
- For this blog purpose I used my sitecore 8.2 demo site- and visited below pages.
Page Visited Date Time http://sitecore8/ 08-06-2019| 22:28 http://sitecore8/mypage1 08-06-2019| 22:29 http://sitecore8/mypage2 08-06-2019|22:30 http://sitecore8/mypage3 08-06-2019|22:31 Cookie value for SC_ANALYTICS_GLOBAL_COOKIE:959d3c1789754dbcb9ff9757172af6df|True
- My intention is to capture behavior as same user returns to demo site later on and visits below Pages.(Technically speaking same user comes back to site in new browser session)
Page Visited Date Time http://sitecore8/ 08-06-2019| 22:34 http://sitecore8/mypage2 08-06-2019| 22:37 http://sitecore8/mypage3 08-06-2019| 22:37 http://sitecore8/mypage6 08-06-2019| 22:37 Cookie value for SC_ANALYTICS_GLOBAL_COOKIE:959d3c1789754dbcb9ff9757172af6df|True
- As you see from Date time in # 2 and #3- I have immediately visited the site before the default session would have cleared. To mimic session clear- I have one custom admin Page added which just kills the current browser session with a line of C# code.
Session.Abandon();
- Feel free to grab sessionkill.aspx file and place it in your web-root folder – (Website\sitecore\admin\sessionkill.aspx)
- I was able to kill current session using- http://sitecore8/sitecore/admin/sessionkill.aspx
- As you see from Date time in # 2 and #3- I have immediately visited the site before the default session would have cleared. To mimic session clear- I have one custom admin Page added which just kills the current browser session with a line of C# code.
- Next I need to verify if my contact and corresponding page visits in both sessions were saved in Mongo DB.
- I have used Robo 3T to connect to my mongo DB
- Contact is saved inside Contacts collection.
- Now we need to have mongoDB query to fetch data from Contacts Collection and verify it for the above anonymous user.
- Contact Id from sc_analytics needs to be encoded to be used in the mongoDB query.
- Grab SC_ANALYTICS_GLOBAL_COOKIE value and get the query using C# snippet available at dotnetfiddle.net
- Grab the query from output window and execute it against Contacts Collection.
Robomongodb.getCollection('Contacts').find({_id:new BinData(3, 'FzydlXWJvE25/5dXFyr23w==')})
Contact Collection So we can now confirm that our anonymous Contact has been saved in Contact Collection which we have verified based on sc_analytics_global_cookie value.
- All the user Page visits are saved to Interactions collection. Grab the ContactId from above output and place it in below snippet(just replace the orange text: #Your ContactId based on above output) to generate query for retrieval of user interactions.
db.getCollection('Interactions').find({"ContactId" : LUUID("173c9d95-7589-bc4d-b9ff-9757172af6df")})
Execute Query:Interaction Collection Above output confirms both sessions has been tracked in interaction Collection.
- Expand each interaction record in the above output window to verify if the corresponding Pages were tracked.
Interaction Collection:Record 1 Verified:All the Pages user visited in #2 – can be verified from this output.
Interaction Collection:Record 2 Verified:All the Pages user visited in #3 – can be verified from this output.
- I have used Robo 3T to connect to my mongo DB
- Sitecore relies on cookies to track anonymous contacts – cookie name:SC_ANALYTICS_GLOBAL_COOKIE
So, in this blog I tried penning down my experience of figuring out the corresponding anonymous contact and their corresponding Page visits in Mongo DB.
Happy Sitecoring !!