Hi Developer D365,
I would merge point 1 and point 2, because they could be concluded into one answer:
Currently the only way to access contact interaction data is by msdyncrm_LoadInteractionsPublic action, by the action we can retrieve interactions such FormSubmitted, FormVisited, WebsiteClicked or WebsiteVisited.
If user visits the page again after 15 days, then a new WebsiteVisited interaction record will be created in corresponding contacts' Insights tab.
Below is example for how to retrieve a specific contact WebsiteVisited interaction:
JS:
var contactId = Xrm.Page.data.entity.getId().replace('{','').replace('}','').toLowerCase();
var data =
{
"InteractionType": "WebsiteVisited",
"ContactId": contactId
};
var req = new XMLHttpRequest();
req.open("POST", parent.Xrm.Page.context.getClientUrl() "/api/data/v9.1/msdyncrm_LoadInteractionsPublic", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
var formatData = JSON.parse(results.Data);
for (var i = 0; i < formatData.length; i ) {
console.log(formatData[i]);
}
} else {
alert(this.response);
}
}
};
req.send(JSON.stringify(data));
C#:
OrganizationRequest req = new OrganizationRequest("msdyncrm_LoadInteractionsPublic");
req["InteractionType"] = "WebsiteVisited";
req["ContactId"] = "xxxx";
OrganizationResponse response = organizationService.Execute(req);
if (response["Data"] != null)
{
JArray a = JArray.Parse(response["Data"].ToString());
Console.WriteLine(a.ToString());
}
else
{
Console.WriteLine("No WebsiteVisited interaction data is found for current contact.");
}
Regards,
Clofly