ウォークスルー
・保存する方法

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

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

このトピックでは、訪問数の総数とすべての訪問の総価値をユーザーエージェントに対してグループ化する古典的なインタラクション集約プロセッサの作成方法を示します。

!注性能向上のために、従来のインタラクションプロセッサを バッチインタラクションプロセッサ にアップグレードすることを推奨します。

あなたは以下を作ります:

  • ディメンションテーブルは、IDを持つユニークなユーザーエージェントのリストを格納する参照テーブルです。
  • ファクトテーブルで、ユーザーエージェントIDを総訪問数とそのエージェントが生み出した価値と比較して保存します。
  • 事実および次元クラスは、事実および次元テーブルのデータをモデル化します。
  • インタラクション集約プロセッサは、事実クラスとディメンションクラスを使ってレポートデータベースのテーブルを埋めます。

次元クラスとテーブルの作成

ディメンションテーブルはユーザーエージェントの文字列のリストを格納します。各ユーザーエージェントは一意のIDを持っています。ディメンションテーブルはファクトテーブルによって参照されており、ファクトテーブルは訪問数の総数とすべての訪問の合計値をユーザーエージェントのIDに対して保存します。

次元クラスの作成

すべての次元には、その次元固有のキーと値クラスがあります。この場合、それらはUserAgentNameKey (例キー: -1743424285)とUserAgentNameValue (例: Chrome)です。

  1. 次元キークラスを作成する:

    namespace Documentation.Examples { using Sitecore; using Sitecore.Analytics.Aggregation.Data.Model; using Sitecore.Analytics.Core;

    public class UserAgentNameKey : DictionaryKey { private readonly Hash32 userAgentNameId;

    public Hash32 UserAgentNameId { get { return this.userAgentNameId; } } public UserAgentNameKey(Hash32 userAgentNameId) { this.userAgentNameId = userAgentNameId; } } }

  2. 次元値クラスを作成する:

    namespace Documentation.Examples { using Sitecore; using Sitecore.Analytics.Aggregation.Data.Model; using Sitecore.Analytics.Core;

    public class UserAgentNameValue : DictionaryValue { private readonly string userAgentName;

    CanBeNull public string UserAgentName { get { return this.userAgentName; } }

    public UserAgentNameValue(CanBeNull string userAgentName) { this.userAgentName = userAgentName; } } }

  3. UserAgentNameKeyとUserAgentNameValueクラスを使用する次元クラスを作成します:

    namespace Documentation.Examples { using Sitecore; using Sitecore.Analytics.Aggregation.Data.Model; using Sitecore.Analytics.Core;

    public class UserAgentName : Dimension<UserAgentNameKey, UserAgentNameValue> { public UserAgentName() { }

    public Hash32 Add(CanBeNull string userAgentName) { string userAgentNameValue = (userAgentName ?? string.Empty); Hash32 result = Hash32.Compute(userAgentNameValue);

    UserAgentNameKey key = new UserAgentNameKey(result); UserAgentNameValue value = new UserAgentNameValue(userAgentNameValue);

    this.Add(key, value);

    return result; } } }

次元表の作成

!重要次元テーブルはクラスと同じ名前を持つべきです。例えば、UserAgentNameクラスはクラスのプロパティに一致する列を持つマッチングdbo.UserAgentNameテーブルを持つべきです。

  • 報告データベースで以下の表を作成します:

    CREATE TABLE dbo.UserAgentName ( UserAgentNameId INT NOT NULL, UserAgentName NVARCHAR (1000) NOT NULL, CONSTRAINT PK_UserAgentNames PRIMARY KEY CLUSTERED (UserAgentNameId ASC) );

    GO

factクラスとテーブルを作成する

ディメンションテーブルは、ユーザーエージェントIDのリストと、そのユーザーエージェントが生成した訪問数および訪問総価値を保存します。

事実クラスの作成

  1. 事実値クラスを作成する:

    namespace Documentation.Examples { using System; using Sitecore; using Sitecore.Analytics.Aggregation.Data.Model; using Sitecore.Analytics.Core; using Sitecore.Diagnostics;

    public class UserAgentValue : DictionaryValue { public long Visits { get; set; } public long Value { get; set; }

    // // Reduces two objects into one by // adding corresponding members together. // NotNull internal static UserAgentValue Reduce(NotNull UserAgentValue left, NotNull UserAgentValue right) { Debug.ArgumentNotNull(left, "left"); Debug.ArgumentNotNull(right, "right"); UserAgentValue result = new UserAgentValue(); result.Visits = (left.Visits + right.Visits); result.Value = (left.Value + right.Value); return result; } } }

    !注Reduce() メソッドは、2つの事実値を加算できるように実装されなければなりません。

  2. ファクトキークラスの作成:

    namespace Documentation.Examples { using System; using Sitecore; using Sitecore.Analytics.Aggregation.Data.Model; using Sitecore.Analytics.Core; using Sitecore.Diagnostics;

    public class UserAgentFactKey : DictionaryKey { public DateTime Date { get; set; } public Hash32 Checksum { get; set; } public Hash32 UserAgentNameId { get; private set; }

    public UserAgentFactKey(Hash32 userAgentHash32) { UserAgentNameId = userAgentHash32; } } }

  3. UserAgentFactKeyとUserAgentValueクラスを使用するファクトクラスを作成します:

    namespace Documentation.Examples { using System; using Sitecore; using Sitecore.Analytics.Aggregation.Data.Model; using Sitecore.Analytics.Core; using Sitecore.Diagnostics;

    public class UserAgentFact : Fact<UserAgentFactKey, UserAgentValue> { public UserAgentFact() : base(UserAgentValue.Reduce) { } } }

ファクトテーブルの作成

ファクトテーブルはクラスと同じ名前で、接頭辞にFact_を付けるべきです。例えば、UserAgentFact factクラスはクラスプロパティに一致する列を持つマッチングdbo.Fact_UserAgentFactテーブルを持ちます。

  • 報告データベースで以下の表を作成します:

    CREATE TABLE dbo.Fact_UserAgentFact ( Date SMALLDATETIME NOT NULL, Checksum INT NOT NULL, UserAgentNameId INT NOT NULL, Visits BIGINT NOT NULL, Value BIGINT NOT NULL, CONSTRAINT FK_Fact_UserAgentFact_UserAgentName FOREIGN KEY (UserAgentNameId) REFERENCES dbo.UserAgentName (UserAgentNameId), );

    GO ALTER TABLE dbo.Fact_UserAgentFact NOCHECK CONSTRAINT FK_Fact_UserAgentFact_UserAgentName;

    GO CREATE NONCLUSTERED INDEX IX_ByDateAndUserAgent ON dbo.Fact_UserAgentFact(Date ASC, UserAgentNameId ASC) INCLUDE(Visits, Value);

    GO CREATE CLUSTERED INDEX IX_ByDate ON dbo.Fact_UserAgentFact(Date ASC, Checksum ASC);

    GO CREATE NONCLUSTERED INDEX IX_Fact_UserAgentFact_UserAgent ON dbo.Fact_UserAgentFact(UserAgentNameId ASC);

インタラクション集約プロセッサクラスを作成する

InteractionAggregationPipelineProcessorを継承するクラスを作成します。以下の例は、前述のステップで作成された事実および次元クラスを使用しています。プロセッサは自動的に事実と次元のテーブルを埋めます。

namespace Documentation.Examples { using System; using Sitecore; using Sitecore.Analytics.Aggregation; using Sitecore.Analytics.Aggregation.Data.Model; using Sitecore.Analytics.Aggregation.Pipeline; using Sitecore.Analytics.Core; using Sitecore.Diagnostics;

public class UserAgentProcessor : InteractionAggregationPipelineProcessor { protected override void OnProcess(InteractionAggregationPipelineArgs args) { var useragent = args.Context.Interaction.UserAgent;

if (string.IsNullOrEmpty(useragent)) { return; }

// // Create the fact key // Hash32 userAgentId = UpdateUserAgentDimension(useragent, args.Context.Results); UserAgentFactKey key = new UserAgentFactKey(userAgentId); key.Date = args.DateTimeStrategy.Translate(args.Context.Interaction.StartDateTime); key.Checksum = Hash32.Compute(userAgentId);

// // Create the fact value. // UserAgentValue value = new UserAgentValue(); value.Visits = 1; value.Value = args.Context.Interaction.EngagementValue;

// // Emit fact. // UserAgentFact facts = args.Context.Results.GetFact(); facts.Emit(key, value); } protected static Hash32 UpdateUserAgentDimension(string useragent, IInteractionAggregationResults results) { Assert.ArgumentNotNull(useragent, nameof(useragent)); Assert.ArgumentNotNull(results, nameof(results));

UserAgentName dimension = results.GetDimension(); Hash32 result = dimension.Add(useragent);

return result; } } }

!notexConnect Client APIのような ファセットやサービス には、インタラクションアグリゲーションプロセッサの文脈でアクセスできます。

プロセッサを構成に追加

プロセッサを図示したように構成にパッチを当てます:

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