Data collection clients

The following article lists .NET SDK data collection clients, along with their constructors, methods, and some sample code.

Interaction client

RECOMMENDATION: We recommend using InteractionClient to report sentences, metadata (both subject and object), and mappings to Insight since version 1.1.5 of the .NET SDK.

Constructors

  • public InteractionClient(string datacenterKey)
    This is your default choice for instantiating the InteractionClient. You need to provide the API Key of the data center you wish to report data to. The client automatically targets the default live instance of the United States Insight API Server.
  • public InteractionClient(string serverAddress, string datacenterKey)
    This constructor takes an additional server address parameter, making it possible to target a Insight API Server different than the default United States one.

Methods

  • public Task<IImportResult> ImportInteractions(string dataSource, IEnumerable<Interaction> interactions)
    Used to report a collection of interactions under the provided data source.
  • public Task<IImportResult> ImportInteraction(string dataSource, Interaction interaction)
    Used to report a single interaction under the provided data source.

Sample code

The example below demonstrates how to report a sentence, subject, and object metadata, and a mapping with single interaction to the website data source. Note that the client does not require you to authenticate:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.DigitalExperienceCloud.Client;
namespace Sitefinity.Insight.Snippets
{
public class InteractionClientSingleInteraction
{
public static void ImportInteraction()
{
string dataCenterKey = "c27aeeb7-d222-d848-d8bf-9792485dafa9";
var interactionClient = new InteractionClient(dataCenterKey);
var interaction = new Interaction()
{
Subject = "john.smith@mail.com",
Predicate = "Visit",
Object = "Home Page"
};
interaction.SubjectMetadata.Add("Email", "john.smith@mail.com");
interaction.ObjectMetadata.PageId = "home-1463";
interaction.ObjectMetadata.Add("Page Name", "Out Home Page");
interaction.MappedTo.Add(new Mapping("mobile", "john.smith@mobile.com"));
interactionClient.ImportInteraction("website", interaction).Wait();
}
}
}

You can also send multiple interactions, for example, metadata and mapping without explicit feature (predicate and object) action specified in them:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.DigitalExperienceCloud.Client;
namespace Sitefinity.Insight.Snippets
{
public class InteractionClientMultipleInteractions
{
public static void ImportInteractions()
{
string dataCenterKey = "c27aeeb7-d222-d848-d8bf-9792485dafa9";
InteractionClient interactionClient = new InteractionClient(dataCenterKey);
Interaction justMetadata = new Interaction()
{
Subject = "john.smith@mail.com"
};
justMetadata.SubjectMetadata.Add("Email", "john.smith@mail.com");
Interaction justMapping = new Interaction()
{
Subject = "john.smith@mail.com"
};
justMapping.MappedTo.Add(new Mapping("mobile", "john.smith@mobile.com"));
var result = interactionClient.ImportInteractions("website", new List<Interaction> { justMetadata, justMapping }).Result;
}
}
}

Sentence client

IMPORTANT: The Sentence client API is included in the latest versions of SDK for backwards compatibility only. We recommend replacing the sentence client with the new InteractionClient.

Subject mapping client

IMPORTANT: The Subject mapping client is included in the latest versions of the SDK for backward compatibility only. We recommend replacing the subject mapping client with the new InteractionClient.
string dataCenterKey = "c27aeeb7-d222-d848-d8bf-9792485dafa9";
SubjectMappingClient mappingClient = new SubjectMappingClient(dataCenterKey);
SubjectMapping mapping = new SubjectMapping()
{
Subject1 = "john.smith",
Source1 = "website",
Subject2 = "john.smith@mobile",
Source2 = "mobile"
};
mappingClient.ImportSubjectMapping(mapping).Wait();

Was this article helpful?