1. ファセット

コア コレクション モデル ファセットを使用する

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

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

xConnectは、いくつかの組み込みファセットを定義します。これらのファセットは、Sitecore.XConnect.Collection.Model名前空間にあります。

コア コレクション モデルの参照

次の例は、独自のモデルでSitecore.XConnect.Collection.Model.CollectionModel.Modelを参照する方法を示しています。

xdbModelBuilder modelBuilder = new XdbModelBuilder("ModelName", new XdbModelVersion(0,1));
modelBuilder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);

コア・コレクション・モデル・ファセットの使用

コア コレクション モデル内でファセットを操作するには、次に示すように既定のファセット キーを使用します。

var avatarFacet = contact.GetFacet<Avatar>(Avatar.DefaultFacetKey);

すべての組み込みファセットには、DefaultFacetKeyプロパティ ( PersonalInformation.DefaultFacetKeyなど) で表されるデフォルトのファセット キーがあります。

コンタクトファセット

個人情報(PersonalInformation)

PersonalInformationファセットには必須のプロパティはありません。

PersonalInformation personal = new PersonalInformation();

personal.Birthdate = new DateTime(1901, 01, 20, 0, 0, 0, DateTimeKind.Utc);
personal.JobTitle = "xDB Enthusiast";
personal.LastName = "McSitecore";
personal.MiddleName = "";
personal.FirstName = "Myrtle";
personal.Gender = "Female";
personal.PreferredLanguage = "English";
personal.Suffix = "the Magnificent";
personal.Title = "Miss";
personal.Nickname = "Myrtle the Cool";

client.SetFacet<PersonalInformation>(new FacetReference(contact, PersonalInformation.DefaultFacetKey), personal);

クライアントで .SetPersonal() 拡張機能を使用することもできます。

client.SetPersonal(contact, personal);

メールアドレスリスト

var preferredEmail = new EmailAddress("[email protected]", true);
var preferredKey = "Work";

var emailFacet = new EmailAddressList(preferredEmail, preferredKey)
{
    Others = new Dictionary<string, EmailAddress>()
    {
        { "Spam",  new EmailAddress("[email protected]", false) }
    },
};

client.SetFacet<EmailAddressList>(new FacetReference(contact, EmailAddressList.DefaultFacetKey), emailFacet);
大事な

優先するメールアドレスは .Othersリストには含まれません。

クライアントで .SetEmails() 拡張機能を使用することもできます。

client.SetEmails(contact, emailFacet);

アドレスリスト

// Preferred address
Address preferredAddress = new Address()
{
    AddressLine1 = "Slartibartfast Mansion",
    AddressLine2 = "42",
    AddressLine3 = "Douglas Road",
    AddressLine4 = "Adams Common",
    City = "Sqornshellous",
    CountryCode = "UK",
    GeoCoordinate = new GeoCoordinate(51.507351f, -0.127758f),
    PostalCode = "AB1 2CD",
    StateOrProvince = "Dragonville"
};

AddressList addressList = new AddressList(preferredAddress, "Home");

Address workAddress = new Address()
{
    AddressLine1 = "44 Work Street",
    City = "Work City",
    CountryCode = "DK"
};

addressList.Others.Add("Work", workAddress);
大事な

優先アドレスは .Othersにリストされていません。

クライアントで .SetAddresses() 拡張機能を使用することもできます。

client.SetAddresses(contact, addressList);

電話番号リスト

var countryCode = "44";
var number = "(555) 555-5555"

PhoneNumber mainNumber = new PhoneNumber(countryCode, number)
{
    Extension = "5",
    AreaCode = "917"  
};

PhoneNumberList numbers = new PhoneNumberList(mainNumber, "Home");

PhoneNumber mobileNumber = new PhoneNumber()
{
    CountryCode = "44",
    Number = "07912345678"
};

numbers.Others.Add("Mobile", mobileNumber);
大事な

優先電話番号はOthersリストには含まれていません。

クライアントで .SetPhoneNumbers() 拡張機能を使用することもできます。

client.SetPhoneNumbers(contact, numbers);

同意事項

メモ

ConsentInformationファセットはSitecore 10.0で変更されました。

次の例は、ConsentInformationファセット クラスのインスタンスを設定し、ディクショナリに2つの同意項目 (1つはデフォルト サイト(website)、もう1つはカスタム サイト(subsite))を追加する方法を示しています。

var consentInformation = new ConsentInformation();

consentInformation.Consents.Add("website", new ConsentItem
{
    ConsentDateTime = DateTime.UtcNow,
    ConsentValue = 1 // Consent given
});

consentInformation.Consents.Add("subsite", new ConsentItem
{
    ConsentDateTime = DateTime.UtcNow,
    ConsentValue = 0 // Consent not given
});

consentInformation.Consents["website"].ConsentValue = 0; // Update consent
consentInformation.Consents["website"].ConsentDateTime = DateTime.UtcNow; // Update consent time

EXMには、doNotMarketconsentRevokedの値を読み取って変更するための拡張メソッドが用意されています。

var doNotMarket = consentInformation.IsDoNotMarket();
var consentRevoked = consentInformation.IsConsentRevoked();

クライアントで .SetConsentInformation() 拡張機能を使用することもできます。

client.SetConsentInformation(contact, consent);

リストサブスクリプション

ListSubscriptions subscriptions = new ListSubscriptions();

var listId = Guid.NewGuid(); /* Replace with real list ID */
var isActive = true;
var added = DateTime.UtcNow;

ContactListSubscription subscription = new ContactListSubscription(added, isActive, listId);

subscriptions.Subscriptions.Add(subscription);

クライアントで .SetListSubscriptions() 拡張機能を使用して、このファセットを設定できます。

client.SetListSubscriptions(contact, subscriptions);

連絡先リストの定義を取得する

ContactListSubscriptionには、IDリストが格納されます。リストに関する詳細 (リスト名など) にアクセスする場合は、連絡先リスト定義マネージャー (Marketing Operations APIの一部です) を使用します。

AutomationPlanEnrollmentCache

AutomationPlanEnrollmentCacheには、コンタクトの現在の自動化プラン登録(登録されているアクティビティーを含む)が含まれています。このファセットは、コンタクトが新しいプランまたはアクティビティに登録されるたびに、Automation Engineによって設定されます。

大事な

このファセットを手動で設定しないでください。 これは、Marketing Automation Operations APIによって更新されます。

AutomationPlanEnrollmentCache enrollmentCache = new AutomationPlanEnrollmentCache();

foreach (var enrollment in enrollmentCache.ActivityEnrollments)
{
    Guid activityID = enrollment.ActivityId;
    Guid planID = enrollment.AutomationPlanDefinitionId;
    DateTime entryDate = enrollment.ActivityEntryDate; // Entry date for activity
    string contextKey = enrollment.ContextKey;
}

このファセットを取得するには:

var facet = contact.GetFacet<AutomationPlanEnrollmentCache>(AutomationPlanEnrollmentCache.DefaultFacetKey);

プランとアクティビティの定義を取得する

AutomationPlanEnrollmentには、アクティビティIDと計画IDが格納されます。プランまたはアクティビティ ( namesなど) に関する詳細にアクセスする場合は、オートメーション プラン定義マネージャー (これはMarketing Operations APIの一部です) を使用します。

アバター

var pictureByteArray = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
var mimeType = "image/jpeg";

Avatar avatar = new Avatar(pictureByteArray, mimeType);

このファセットを取得するには:

var facet = contact.GetFacet<Avatar>(Avatar.DefaultFacetKey);

クライアントで .SetAvatar() 拡張機能を使用することもできます。

client.SetAvatar(contact, avatar);

計算されたコンタクトファセット

次の 計算されたコンタクトファセット がデフォルトで使用可能です。

大事な

計算されたファセットの値は決して設定しないでください - インタラクションがxConnectに送信されるたびにサービス プラグインによって設定されます。

インタラクションファセット

ユーザーエージェント情報

UserAGentInfo userAgentInfo = new UserAgentInfo();

userAgentInfo.CanSupportTouchScreen = true;
userAgentInfo.DeviceType = "Mobile";
userAgentInfo.DeviceVendor = "HTC"
userAgentInfo.DeviceVendorHardwareModel = "HTC Desire"

イップインフォ

var ipAddress = "8, 8, 8, 8";

IpInfo ipInfo = new IpInfo(ipAddress);

ipInfo.Isp = "Super Duper Internet";
ipInfo.Latitude = 55.673977;
ipInfo.Longitude = 12.568730;
ipInfo.MetroCode = "408";
ipInfo.AreaCode = "205";
ipInfo.BusinessName = "Bizniz";
ipInfo.City = "Super City";
ipInfo.Country = "Narnia";
ipInfo.PostalCode = "12A 24B";
ipInfo.Region = "Icy Plains";
ipInfo.Url = "host.local";
ipInfo.Dns = "dnsvalue";

このファセットを取得するには:

var facet = interaction.GetFacet<IpInfo>IpInfo.DefaultFacetKey);

クライアントで .SetIpInfo() 拡張機能を使用することもできます。

client.SetIpInfo(interaction, ipInfo);

プロフィールスコア

ProfileScore profileScore = new ProfileScore()
{
    MatchedPatternId = Guid.NewGuid(), // Guid of matched profile
    ProfileDefinitionId = Guid.NewGuid(), // Guid of profile
    Score = 1.9f,
    ScoreCount = 3,
    Values = new Dictionary<Guid, float>() { { Guid.NewGuid(), 1.2f }, { Guid.NewGuid(), 1.2f } }
};

ProfileScores profiles = new ProfileScores();

profiles.Scores.Add(Guid.NewGuid(), profileScore);

// NOTE: The Scores dictionary key should be the profile definition ID as a Guid

ウェブ訪問

WebVisitファセットには、Webサイトで発生したインタラクションに関する情報が格納されます。Sitecoreのコンテキストでは、このファセットはセッション終了時にトラッカーによって入力されます。次の例は、WebVisitファセットを設定し、インタラクションにいくつかのPageViewEventイベントを追加することで、Web訪問を模倣する方法を示しています。

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

namespace Documentation
{
    public class SampleWebVisit
    {
        public async void Example()
        {
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                // Create a new contact and set some facets
                var contact = new Contact();

                var personalInfoFacet = new PersonalInformation()
                {
                    FirstName = "Myrtle",
                    LastName = "McSitecore"
                };

                client.SetPersonal(contact, personalInfoFacet);

                client.AddContact(contact);

                // Create a new interaction for the contact
                Guid channelId = Guid.NewGuid();
                string userAgent = "Sample User Agent";
                Interaction webInteraction = new Interaction(contact, InteractionInitiator.Brand, channelId, userAgent);

                // Create a new web visit facet model
                var webVisitFacet = new WebVisit();

                // Populate data about the web visit
                webVisitFacet.Browser = new BrowserData() { BrowserMajorName = "Chrome", BrowserMinorName = "Desktop", BrowserVersion = "22.0" };
                webVisitFacet.Language = "en";
                webVisitFacet.OperatingSystem = new OperatingSystemData() { Name = "Windows", MajorVersion = "10", MinorVersion = "4" };
                webVisitFacet.Referrer = "www.google.com";
                webVisitFacet.Screen = new ScreenData() { ScreenHeight = 1080, ScreenWidth = 685 };
                webVisitFacet.SearchKeywords = "sitecore";
                webVisitFacet.SiteName = "website";

                var itemId = Guid.NewGuid();
                var itemVersion = 5;

                // First page view
                 pageView = new PageViewEvent(new DateTime(2016, 10, 10, 13, 20, 22).ToUniversalTime(), itemId, itemVersion, "en");

                pageView.ItemLanguage = "en";
                pageView.Duration = new TimeSpan(3000);

                webInteraction.Events.Add(pageView);

                var secondItemId = Guid.NewGuid();
                var secondItemVersion = 2;

                // Second page view
                PageViewEvent pageView2 = new PageViewEvent(new DateTime(2016, 10, 10, 13, 21, 22).ToUniversalTime(), secondItemId, secondItemVersion, "en");

                pageView.ItemLanguage = "en";
                pageView.Duration = new TimeSpan(3200);

                webInteraction.Events.Add(pageView2);

                // First goal, associated with second page view
                Goal goal1 = new Goal(Guid.NewGuid(), new DateTime(2016, 10, 10, 13, 22, 22).ToUniversalTime());

                goal1.ParentEventId = pageView2.Id;

                webInteraction.Events.Add(goal1);

                var thirdItemId = Guid.NewGuid();
                var thirdItemVersion = 2;

                // Third page view
                PageViewEvent pageView3 = new PageViewEvent(new DateTime(2016, 10, 10, 13, 22, 22).ToUniversalTime(), thirdItemId, thirdItemVersion, "en");

                pageView.ItemLanguage = "en";
                pageView.Duration = new TimeSpan(1200);

                webInteraction.Events.Add(pageView3);

                // Set web visit facet on interaction
                client.SetWebVisit(webInteraction, webVisitFacet);

                // Add interaction
                client.AddInteraction(webInteraction);

                // Submit contact and interaction
                await client.SubmitAsync(); // Synchronous version - client.SubmitAsync().GetAwaiter().GetResult();
            }
        }
    }
}

ロケール情報

LocaleInfo localeInfo = new LocaleInfo();

localeInfo.TimeZoneOffset = new TimeSpan(200);
localeInfo.GeoCoordinate = new GeoCoordinate(1.11111f, 2.22222f);

クライアントで .SetLocaleInfo() 拡張機能を使用することもできます。

client.SetLocaleInfo(interaction, localeInfo);

ファセットのget/set拡張メソッド

クラスにusingSitecore.XConnect.Collection.Modelを追加すると、コンタクト、インタラクション、xConnectクライアントのさまざまな拡張メソッドにアクセスして、ビルトイン ファセットの取得と設定が容易になります。たとえば、myContact.Personal() は次のメソッドを呼び出します。

public static PersonalInformation Personal(this Contact c)
{
    return c.GetFacet<PersonalInformation>(PersonalInformation.DefaultFacetKey);
}

同様に、client.SetAddresses(myContactObject,myFacetObject) は次のメソッドを呼び出します。

public static SetFacetOperation<AddressList> SetAddresses(this XdbContext context, IEntityReference<Contact> contact, AddressList facet)
{
    return context.SetFacet(new FacetReference(contact, PersonalInformation.DefaultFacetKey), facet);
}
この記事を改善するための提案がある場合は、 お知らせください!