Display Sitecore analytic information such as Pages Visited, Duration of the Visit, Time of the Visit and Goals triggered based on email address of the website visitor and publish the same to Salesforce CRM.
Why to Save Sitecore contact’s analytical data on Salesforce?
Saving Sitecore contact’s analytical data on salesforce along with the personal information (Name, Email Address, Mobile Number) provided by the visitor helps the Sales/Marketing team in better understanding about the contact. It helps them in understanding the visitor’s behavioral pattern or product he/she is most interested in without going back to Sitecore to check Analytical data in Experience profile.
Fetching analytics information of a contact from Sitecore in an API call when Sitecore.Analytics.Tracker is null.
For example, if you want to fetch and publish the analytics data when the user submits the form or trigger certain action, we can use Sitecore.Analytics.Tracker to find the current contact and get all the information about the Contact.
However, in API call or Sitecore scheduling agents Analytics.Tracker cannot be used as Analytics.Tracker returns null.
Using default class provided by Sitecore called “Contact Repository”.
What is Contact Repository?
Contact repository is the default class provided by Sitecore that helps you perform various operations on Sitecore contacts such as Contact creation, Merge contact, load contact historical data etc.
Contact repository helps you to identify the contacts and fetch necessary information about the contact even when Analytics.Tracker is null.
- Reference to following dlls
- Install MongoDB.
- Enable Sitecore Analytics.
- Make sure that Salesforce account you are using have appropriate access rights to Write data to Salesforce.
public async Task<bool> ContactInfo(string maildId, string salesforceContactID, ForceClient client)
List<string> urls = new List<string>();
Sitecore_Analytics__c analytics = new Sitecore_Analytics__c();
//Get contact based on email address of the contact
var contact = contactRepository.LoadContactReadOnly(maildId);
if (contact != null)
contact.Identifiers.Identifier = maildId;
//Load 10 historical interactions data of sitecore contact
var data = contact.LoadHistorycalData(10);
//Pages visited by the contact
var pagesVisisted = data.Where(x => x.ContactId == contact.ContactId).First().Pages;
//Get previous interactions of the contact
var interactions = data.Where(x => x.ContactId == contact.ContactId);
var interaction = interactions.OrderByDescending(x => x.StartDateTime).LastOrDefault();
foreach (var page in interaction.Pages.OrderByDescending(x=>x.DateTime).Take(5))
analytics.Page_Url__c = page.Url.ToString();
analytics.Start_Time__c = page.DateTime;
analytics.Duration__c = page.Duration;
analytics.Contact_Name__c = salesforceContactID;
SuccessResponse sr1 = await client.CreateAsync("Sitecore_Analytics__c", analytics);
Log.Info("Analytics pushed to Salesforce ", this);
Log.Info("Failed to push Analytics to Salesforce", this);
As you can see below, respective page visits for the Lead/Contact selected are now shown in Salesforce. For highly engaged Sales Qualified Leads (SQL) this feature will readily help Sales person to understand the lead/customer intentions and form a contextual pitch in their interactions.