Monday, February 26, 2018

Code Your Way Corner How to implement Cross-Site In-Session Sitecore Analytics

I came across this weird scenario wherein we were migrating old legacy project coded in Vb.net into Sitecore. So during this process, we had to migrate in a prioritized manner which made difficult to share analytics across two different projects. So I have just noted down what I did in order to accomplish the same.

Assume we have a scenario with two different projects which are utilized for same Website (Some pages in Sitecore and Some pages in any other framework ). Let's Assume Sitecore Project named as "CodeYourWaySitecore" and other project named as  "CodeYourWayLegacy"
For CodeYourWaySitecore and CodeYourWayLegacy (“CodeYourWayLegacy.demo.com” and “CodeYourWayLegacy.demo.com”)  are hosted on different websites.  
By default in session, analytics work for each individual site.  Identifying and merging contacts at the end of the session allows for post-session interactions(assuming the contacts have been identified) but does nothing to address the user interactions on both sites.  Out of the box, no personalization on the CodeYourWaySitecore would kick in based on the interaction triggered on the CodeYourWayLegacy until after session end.
It turns out that you can share an analytics session assuming that the sites in question share a domain and you have a shared session database:
  1. Configure shared session cookies based on a domain by adding “ <httpCookies domain=”.demo.com”/>” (with your domain name of choice of course) in the system.web section of the web.config of both projects.
  2. Configure a shared session state database (instructions for 8.2 are here (Please note that while you use session DB it should be Sitecore session DB, For example: If your Sitecore instance is CodeYourWaySitecore then it would be CodeYourWaySitecore_Sessions)


If you want to add some diagnostics to view this real time, you can access the Tracker.Current.Session.Interaction data.  You will see it contains the same ContactId and InteractionId for both websites and the pages collection including page visits and goals triggered are in sync across both sites as well.
Voila – Analytics/ Interactions now works for both the sites exactly the same as it normally does for a single site.

Let me know if you face any difficulty in setting up.  


via MJ-Space

Other Sites :
Code Your Way | Travel Guide

No comments:

Post a Comment