1. インタラクションを得て

インタラクションイベントを取得

Version:
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

イベントはInteractionオブジェクトのEventsプロパティ上で利用可能である。すべての相互作用には少なくとも一つのイベントがある。

イベントの種類別に取得

以下の例は、タイムスタンプ順に、相互作用中に発生したGoalイベントのリストを取得する方法を示しています。

using Sitecore.XConnect.Collection.Model; using Sitecore.XConnect; using System; using System.Linq; using Sitecore.XConnect.Client;

namespace Documentation { public class GetInteractionEvents { // Async example public async void ExampleAsync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try {

// Contact reference from ID var contactRef = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB")); Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

var interactionTask = client.GetAsync(interactionRef, new InteractionExecutionOptions(new InteractionExpandOptions(IpInfo.DefaultFacetKey)));

Interaction interaction = await interactionTask;

if (interaction != null) { var events = interaction.Events;

// Get all goals var goals = interaction.Events.OfType().OrderBy(ev => ev.Timestamp).ToList(); } } catch (Exception ex) { // Manage exceptions } } }

// Sync example public void ExampleSync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try {

// Contact reference from ID var contactRef = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB")); Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

Interaction interaction = client.Get(interactionRef, new InteractionExecutionOptions(new InteractionExpandOptions(IpInfo.DefaultFacetKey)));

if (interaction != null) { var events = interaction.Events;

// Get all goals var goals = interaction.Events.OfType().OrderBy(ev => ev.Timestamp).ToList(); } } catch (Exception ex) { // Manage exceptions } } } } }

IDの定義でイベントを取得する

特定の目標、結果、またはページイベントを取得するには、そのイベントのDefinitionIdプロパティでフィルタリングできます。このプロパティは、イベントをトリガーした際に使用されたSitecoreの定義項目のIDです。

DownloadEventのような一部のイベントモデルは、イベントがトリガーされるたびに固定された定義IDを持ち、これはイベントモデルとイベント定義の間に1対1の関係があることを意味します。しかし、Goalイベントモデルは任意の目標定義項目に使用可能です。

次の試験では、定義ID {A4364105-1F45-E611-82E6-34E6D7117DCB} すべての目標を選択します。

using Sitecore.XConnect.Collection.Model; using Sitecore.XConnect; using System; using System.Linq; using Sitecore.XConnect.Client;

namespace Documentation { public class GetEventByDefinition { // Async example public async void ExampleAsync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try {

// Contact reference from ID var contactRef = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB")); Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

var interactionTask = client.GetAsync(interactionRef, new InteractionExecutionOptions(new InteractionExpandOptions(IpInfo.DefaultFacetKey)));

Interaction interaction = await interactionTask;

if (interaction != null) { var events = interaction.Events;

// Get all goals with definition ID {A4364105-1F45-E611-82E6-34E6D7117DCB} var goals = interaction.Events.OfType().Where(x => x.DefinitionId == Guid.Parse("A4364105-1F45-E611-82E6-34E6D7117DCB")); } } catch (XdbExecutionException ex) { // Manage exceptions } } }

// Sync example public void ExampleSync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try {

// Contact reference from ID var contactRef = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB")); Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

Interaction interaction = client.Get(interactionRef, new InteractionExecutionOptions(InteractionExpandOptions(IpInfo.DefaultFacetKey)));

if (interaction != null) { var events = interaction.Events;

// Get all goals with definition ID {A4364105-1F45-E611-82E6-34E6D7117DCB} var goals = interaction.Events.OfType().Where(x => x.DefinitionId == Guid.Parse("A4364105-1F45-E611-82E6-34E6D7117DCB")); } } catch (XdbExecutionException ex) { // Manage exceptions } } } } }

ページビューイベントを見る

ウェブ上のやり取りでは、ページビューはPageViewEventモデルで表されます。以下の例は、PageViewEventイベントのリストを取得する方法を示しています。

using Sitecore.XConnect.Collection.Model; using Sitecore.XConnect; using System; using System.Linq; using Sitecore.XConnect.Client;

namespace Documentation { public class PageView { public async void Example() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try {

// Contact reference from ID var contactRef = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB")); Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

var interactionTask = client.GetAsync(interactionRef, new InteractionExecutionOptions(new InteractionExpandOptions(IpInfo.DefaultFacetKey)));

var interaction = await interactionTask;

var events = interaction.Events;

var pageViews = interaction.Events.OfType().OrderBy(ev => ev.Timestamp).ToList(); } catch (XdbExecutionException ex) { // Handle exception } } }

// Sync example public void ExampleSync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try {

// Contact reference from ID var contactRef = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB")); Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

var interaction = client.Get(interactionRef, new InteractionExecutionOptions(new InteractionExpandOptions(IpInfo.DefaultFacetKey)));

var events = interaction.Events;

var pageViews = interaction.Events.OfType().OrderBy(ev => ev.Timestamp).ToList(); } catch (XdbExecutionException ex) { // Handle exception } } } } }

シーケンス番号によるページビュー取得

VisitPageIndexの直接的な代替はありません。ページビューをTimestamp順に並べる場合は、ElementAt()拡張子を使いましょう。例えば:

var pageViews = interaction.Events.OfType().OrderBy(ev => ev.Timestamp).ToList(); var event = pageViewEvents.ElementAt(3); // Gets fourth page view

特定のページで起こった出来事を入手しましょう

連絡先がページにアクセスすると、PageViewEventがトリガーされます。そのページの文脈では、例えば追加のイベントもトリガーされることがあります。

  • Goal
  • Outcome
  • DownloadEvent
  • SearchEvent
  • CampaignEvent
  • ジェネリックで表されるページイベント Event

あるページの文脈でイベントがトリガーされた場合、そのイベントのParentEventIdがPageViewEventのIdとなります。以下の例は、ページのリストを順に進めて、そのページでトリガーされたすべてのイベントを取得する方法を示しています。

using Sitecore.XConnect.Collection.Model; using Sitecore.XConnect; using System; using System.Linq; using Sitecore.XConnect.Client;

namespace Documentation { public class EventsOnPage { // Async example public async void ExampleAsync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try {

// Contact reference from ID var contactRef = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB")); Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

var interactionTask = client.GetAsync<Sitecore.XConnect.Interaction>(interactionRef, new InteractionExecutionOptions(new InteractionExpandOptions(IpInfo.DefaultFacetKey)));

var interaction = await interactionTask;

// This particular example is web-focused and is getting all events with a parent event of type PageViewEvent var pageViews = interaction.Events.OfType().OrderBy(ev => ev.Timestamp).ToList();

// Create a map of events - this is the most efficient way to work with an interaction that // has many events. It is a general recommendation and not specific to Sitecore. var eventMap = interaction.Events.Where(ev => ev.ParentEventId.HasValue).ToLookup(ev => ev.ParentEventId.Value); var eventGuid = Guid.Parse("c91ce6eb-c346-447e-b65d-1f0f90b520e5"); // Replace with the ID of a real event definition item

// For each page view, get any events where ParentEventId equals ID of the page view event // and the event has a specific definition ID foreach (var pageView in pageViews) { var goalAssociatedWithPageView = eventMappageView.Id.OfType(); var eventAssociatedWithPageView = eventMappageView.Id.OfType().Where(x => x.DefinitionId == eventGuid); } } catch (XdbExecutionException ex) { // Manage exceptions } } }

// Sync example public void ExampleSync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try {

// Contact reference from ID var contactRef = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB")); Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

var interaction = client.Get<Sitecore.XConnect.Interaction>(interactionRef, new InteractionExecutionOptions(new InteractionExpandOptions(IpInfo.DefaultFacetKey)));

// This particular example is web-focused and is getting all events with a parent event of type PageViewEvent var pageViews = interaction.Events.OfType().OrderBy(ev => ev.Timestamp).ToList();

// Create a map of events - this is the most efficient way to work with an interaction that // has many events. It is a general recommendation and not specific to Sitecore. var eventMap = interaction.Events.Where(ev => ev.ParentEventId.HasValue).ToLookup(ev => ev.ParentEventId.Value); var eventGuid = Guid.Parse("c91ce6eb-c346-447e-b65d-1f0f90b520e5"); // Replace with the ID of a real event definition item

// For each page view, get any events where ParentEventId equals ID of the page view event // and the event has a specific definition ID foreach (var pageView in pageViews) { var goalAssociatedWithPageView = eventMappageView.Id.OfType(); var eventAssociatedWithPageView = eventMappageView.Id.OfType().Where(x => x.DefinitionId == eventGuid); } } catch (XdbExecutionException ex) { // Manage exceptions } } } } }

カスタムタイプで表現されていないページイベントを入手してください

特定のページイベントはカスタム型で表現されます。例えばDownloadEvent。イベントがカスタム型で表現されていない場合は、基本のEvent型を使用し、イベントの定義IDでフィルタリングします。

var eventGuid = Guid.Parse("c91ce6eb-c346-447e-b65d-1f0f90b520e5"); // Replace with the ID of a real event definition item

var event = interaction.Events.OfType().Where(x => x.DefinitionId == eventGuid);

キャンペーンIDごとにキャンペーンイベントを取得

CampaignEventには2つの定義IDがあります:

  • DefinitionId はイベント定義項目自体のIDであり、このIDは常に同じです
  • CampaignDefinitionId はキャンペーン定義項目のIDであり、このIDはトリガーされたキャンペーンによって異なります

以下の例では、ID {29814105-2345-E611-AAE6-34E6D7117DCB} を含むキャンペーンを参照するイベントを選択します。

using Sitecore.XConnect.Collection.Model; using Sitecore.XConnect; using System; using System.Linq; using Sitecore.XConnect.Client;

namespace Documentation { public class GetCampaignEvent { // Async example public async void ExampleAsync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try {

// Contact reference from ID var contactRef = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB")); Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

var interactionTask = client.GetAsync<Sitecore.XConnect.Interaction>(interactionRef, new InteractionExecutionOptions(new Sitecore.XConnect.InteractionExpandOptions(IpInfo.DefaultFacetKey)));

var interaction = await interactionTask;

var campaigns = interaction.Events.OfType().Where(x => x.CampaignDefinitionId == Guid.Parse("29814105-2345-E611-AAE6-34E6D7117DCB")).ToList(); } catch (XdbExecutionException ex) { // Manage exceptions } } }

// Sync example public void ExampleSync() { using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try {

// Contact reference from ID var contactRef = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB")); Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

var interaction = client.Get<Sitecore.XConnect.Interaction>(interactionRef, new InteractionExecution Options(new Sitecore.XConnect.InteractionExpandOptions(IpInfo.DefaultFacetKey)));

var campaigns = interaction.Events.OfType().Where(x => x.CampaignDefinitionId == Guid.Parse("29814105-2345-E611-AAE6-34E6D7117DCB")).ToList(); } catch (XdbExecutionException ex) { // Manage exceptions } } } } }

イベントやキャンペーンに関連する定義項目を入手

Sitecoreの文脈では、Marketing Operations APIを使ってイベントやキャンペーンの定義項目を取得することができます。Sitecore以外の文脈では、Reference Data Service Client APIをご利用ください。

!注ランダムなGUIDでイベントをトリガーすることが可能です。しかし、これは報告に悪影響を及ぼします。

この記事を改善するための提案がある場合は、 お知らせください!