Sitecore

Verify Contacts and Page Visits in XDB|Sitecore implementaion

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. 

        1. 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.
        2. For this blog purpose I used my sitecore 8.2 demo site- and visited below pages.
          Page VisitedDate Time
          http://sitecore8/08-06-2019| 22:28
          http://sitecore8/mypage108-06-2019| 22:29
          http://sitecore8/mypage208-06-2019|22:30
          http://sitecore8/mypage308-06-2019|22:31

          Cookie value for SC_ANALYTICS_GLOBAL_COOKIE:959d3c1789754dbcb9ff9757172af6df|True

        3. 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 VisitedDate Time
          http://sitecore8/08-06-2019| 22:34 
          http://sitecore8/mypage208-06-2019| 22:37 
          http://sitecore8/mypage308-06-2019| 22:37 
          http://sitecore8/mypage608-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 
        4. 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
                https://kumarsaurabhrajpoot.files.wordpress.com/2019/06/robo-3t-1.3-2019-06-08-23.03.43.png
              • 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.netcontactRoboQuery
              • Grab the query from output window and execute it against Contacts Collection. Robomongodb.getCollection('Contacts').find({_id:new BinData(3, 'FzydlXWJvE25/5dXFyr23w==')})
                contactCollection

                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:
                interactions

                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.
                interactions

                Interaction Collection:Record 1

                Verified:All the Pages user visited in #2 – can be verified from this output.


                interactions

                Interaction Collection:Record 2

                Verified:All the Pages user visited in #3 – can be verified from this output.

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 !!

Categories: Sitecore, Sitecore 8.2, xDB

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s