目標

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

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

目標定義は、Sitecore.Marketing.Definitions.Goals.GoalDefinitionManagerクラスによって管理されます。

メモ

目標は特別なイベントです。 IGoalDefinitionIEventDefinitionを継承します。

GoalDefinitionManagerへのアクセス

GoalDefinitionManagerは、Sitecore DIコンテナから入手できます。クラスのコンストラクタにDefinitionManagerBase<IGoalDefinition, GoalDefinitionRecord> 型のパラメータを含め、コンテナからクラスをプルして、コンテナがインスタンスを解決できるようにすることをお勧めします。

public MyClass(DefinitionManagerBase<IGoalDefinition, GoalDefinitionRecord> goalDefinitionManager)
{
        ...
}

コンテナを使用してクラスを構築できない場合は、サービス ロケータを使用できます。このクラスは、Sitecore DIコンテナーでも使用できます。

using Sitecore.DependencyInjection;
using Sitecore.Marketing.Definitions;


namespace Documentation
{
        public class DefineAGoal
        {
                public void Example()
                {
                        var goalDefinitionManager = ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<Sitecore.Marketing.Definitions.Goals.IGoalDefinition>();
                }
        }
}

目標の定義

目標は、Sitecore.Marketing.Definitions.Goals.Model名前空間の型を使用して定義されます。

using Sitecore.DependencyInjection;
using Sitecore.Marketing.Definitions;
using System;
using System.Globalization;

namespace Documentation
{
        public class DefineAGoal
        {
                public void Example()
                {
                        var goalDefinitionManager = ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<Sitecore.Marketing.Definitions.Goals.IGoalDefinition>();

                        Guid goalId = Guid.NewGuid(); // Goal ID
                        CultureInfo goalCulture = new CultureInfo("es"); // Goal culture
                        string goalName = "Newly created goal"; // Goal name
                        DateTime creationDate = DateTime.UtcNow; // Goal creation date
                        string createdBy = "sitecore\admin"; // Goal creator

                        Sitecore.Marketing.Definitions.Goals.GoalDefinition goal = new Sitecore.Marketing.Definitions.Goals.GoalDefinition(goalId, "Goal item name", goalCulture, goalName, creationDate, createdBy);

                        goal.ShowInXfileAsLatestEvent = true;
                        goal.ShowInXfileEventsList = true;
                        goal.EngagementValuePoints = 20;

                        goal.IsSystem = false; // Note: This property might be removed
                        goal.IsLiveEvent = false;
                }
        }
}

ライブイベント

IsLiveEventプロパティは基本EventDefinitionクラスの一部であり、イベントをセッション終了時ではなくすぐに処理する必要があるかどうかを判断するためにMarketing Automationによって使用されます。ライブイベント処理の詳細については、こちらをご覧ください。

目標の保存

目標を定義したら、定義マネージャでSaveAsync() メソッドを呼び出して保存できます。

using Sitecore.DependencyInjection;
using Sitecore.Marketing.Definitions;
using System;
using System.Globalization;

namespace Documentation
{
        public class SaveAGoal
        {
                public void Example()
                {
                        var goalDefinitionManager = ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<Sitecore.Marketing.Definitions.Goals.IGoalDefinition>();

                        Guid goalId = Guid.NewGuid(); // Goal ID
                        CultureInfo goalCulture = new CultureInfo("es"); // Goal culture
                        string goalName = "Download Brochure"; // Goal name
                        DateTime creationDate = DateTime.UtcNow; // Goal creation date
                        string createdBy = "sitecore\admin"; // Goal creator

                        Sitecore.Marketing.Definitions.Goals.GoalDefinition goal = new Sitecore.Marketing.Definitions.Goals.GoalDefinition(goalId, "Goal item name", goalCulture, goalName, creationDate, createdBy);

                        goalDefinitionManager.SaveAsync(goal);
                }
        }
}

オプションで、保存中にSaveAsync() メソッドの2番目のパラメーターにtrueを渡すことで、ゴールをアクティブ化することもできます。

manager.SaveAsync(goal, true);

目標の有効化

目標は、管理の外部で使用できるようになる前にアクティブ化する必要があります。ゴールは、SaveAsync()メソッドのactivate (2番目) パラメーターにtrueを渡すことで、ゴールを保存するときにアクティブ化できます。

manager.SaveAsync(goal, true);

ゴールは、ActivateAsync() メソッドを使用して、saveを呼び出さずにアクティブ化することもできます。

manager.ActivateAsync(goalId);

ActivateAsync()メソッドは、目標のIDを取り、目標定義モデルを必要としません。

目標の削除

目標を削除するには、マネージャーでDelete() メソッドを使用します。個々のカルチャを定義から削除することはできず、定義全体のみを削除します。メソッド呼び出しに提供されるカルチャは、null (既定値) またはCultureInfo.InvariantCultureである必要があります。

manager.Delete(goalId);

ゴールを取得する

1つのゴールは、マネージャーのGet() 方法のいずれかを使用してID取得できます。

using Sitecore.DependencyInjection;
using Sitecore.Marketing.Definitions;
using System;
using System.Globalization;

namespace Documentation
{
        public class GetAGoal
        {
                public void Example()
                {
                        var goalDefinitionManager = ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<Sitecore.Marketing.Definitions.Goals.IGoalDefinition>();

                        Guid goalId = Guid.NewGuid(); // Ensure this is the ID of an existing goal

                        // Get by ID and culture. Will get the latest active version
                        Sitecore.Marketing.Definitions.Goals.IGoalDefinition goalOne = goalDefinitionManager.Get(goalId, new CultureInfo("da"));

                        // Get by ID and culture. Will get the latest version, including if the version is inactive
                        Sitecore.Marketing.Definitions.Goals.IGoalDefinition goalWithInactive = manager.Get(goalId, new CultureInfo("da"), true);
                }
        }
}

エイリアスでゴールを取得する

また、エイリアスでゴールを取得することもできます。

CultureInfo goalCulture = new CultureInfo("fr-fr");
var goalDefinitionByAlias = definitionManager.GetByAlias("My alias", goalCulture);

既存の目標を更新する

既存の目標定義を更新するには、IDで目標を取得し、目標を編集します

using Sitecore.DependencyInjection;
using Sitecore.Marketing.Definitions;
using System;
using System.Globalization;

namespace Documentation
{
        public class UpdateAGoal
        {
                public void Example()
                {
                        var goalDefinitionManager = ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<Sitecore.Marketing.Definitions.Goals.IGoalDefinition>();

                        Guid goalId = Guid.NewGuid(); // Ensure this is the ID of an existing goal

                        // Get by ID and culture. Will get the latest active version
                        Sitecore.Marketing.Definitions.Goals.IGoalDefinition goal = goalDefinitionManager.Get(goalId, new CultureInfo("da"));

                        // Make updates to goal
                        goal.Name = "Updated name";

                        // Save to update
                        goalDefinitionManager.SaveAsync(goal);
                }
        }
}

すべての目標の取得

GetAll()方法を使用すると、マネージャーからすべての目標を取得できます。定義が多数ある可能性があるため、このメソッドはページングをサポートします。戻り値は1ページの結果です。

using Sitecore.DependencyInjection;
using Sitecore.Marketing.Definitions;
using System;
using System.Globalization;

namespace Documentation
{
        public class GetAllGoals
        {
                public void Example()
                {
                        var goalDefinitionManager = ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<Sitecore.Marketing.Definitions.Goals.IGoalDefinition>();

                        // Get All with defaults which will be first page, page size 20, latest active versions only
                        Sitecore.Marketing.Core.ResultSet<DefinitionResult<Sitecore.Marketing.Definitions.Goals.IGoalDefinition>> goals = goalDefinitionManager.GetAll(new CultureInfo("da"), new RetrievalParameters<Sitecore.Marketing.Definitions.Goals.IGoalDefinition, string>());

                        // Get page 2
                        Sitecore.Marketing.Core.ResultSet<DefinitionResult<Sitecore.Marketing.Definitions.Goals.IGoalDefinition>> page2Goals = goalDefinitionManager.GetAll(new CultureInfo("da"), new RetrievalParameters<Sitecore.Marketing.Definitions.Goals.IGoalDefinition, string>(pageNumber: 2));

                        // Include inactive versions
                        Sitecore.Marketing.Core.ResultSet<DefinitionResult<Sitecore.Marketing.Definitions.Goals.IGoalDefinition>> page1Goals = goalDefinitionManager.GetAll(new CultureInfo("da"), new RetrievalParameters<Sitecore.Marketing.Definitions.Goals.IGoalDefinition, string>(), true);
                }
        }
}

結果にアクセスするには、結果のDataPageプロパティを使用します。

IGoalDefinition goal = page1Goals.DataPage.ElementAt(0);

この結果には、定義の総数と現在のページ・インデックスおよびページ・サイズを公開するプロパティも含まれます。

long totalDefinitionCount = page1Goals.Total;
int pageNumber = page1Goals.PageNumber;
int pageSize = page1Goals.Count;
この記事を改善するための提案がある場合は、 お知らせください!