コード例 #1
0
        /// <summary>
        /// Create Visitor instance
        /// </summary>
        /// <param name="conversionEvent">The ConversionEvent entity</param>
        /// <param name="logger">The ILogger entity</param>
        /// <returns>Visitor instance if ConversionEvent is valid, null otherwise</returns>
        private static Visitor CreateVisitor(ConversionEvent conversionEvent, ILogger logger)
        {
            if (conversionEvent == null)
            {
                return(null);
            }

            EventContext  userContext   = conversionEvent.Context;
            var           revenue       = EventTagUtils.GetRevenueValue(conversionEvent.EventTags, logger) as int?;
            var           value         = EventTagUtils.GetNumericValue(conversionEvent.EventTags, logger) as float?;
            SnapshotEvent snapshotEvent = new SnapshotEvent.Builder()
                                          .WithUUID(conversionEvent.UUID)
                                          .WithEntityId(conversionEvent.Event.Id)
                                          .WithKey(conversionEvent.Event?.Key)
                                          .WithTimeStamp(conversionEvent.Timestamp)
                                          .WithRevenue(revenue)
                                          .WithValue(value)
                                          .WithEventTags(conversionEvent.EventTags)
                                          .Build();


            Snapshot snapshot = new Snapshot(new SnapshotEvent[] { snapshotEvent });

            var visitor = new Visitor(new Snapshot[] { snapshot }, conversionEvent.VisitorAttributes, conversionEvent.UserId);

            return(visitor);
        }
コード例 #2
0
        /// <summary>
        /// Create Visitor instance
        /// </summary>
        /// <param name="impressionEvent">The ImpressionEvent entity</param>
        /// <returns>Visitor instance if ImpressionEvent is valid, null otherwise</returns>
        private static Visitor CreateVisitor(ImpressionEvent impressionEvent)
        {
            if (impressionEvent == null)
            {
                return(null);
            }

            var eventContext = impressionEvent.Context;

            Decision decision = new Decision(impressionEvent.Experiment?.LayerId,
                                             impressionEvent.Experiment?.Id,
                                             impressionEvent.Variation?.Id,
                                             impressionEvent.Metadata);

            SnapshotEvent snapshotEvent = new SnapshotEvent.Builder()
                                          .WithUUID(impressionEvent.UUID)
                                          .WithEntityId(impressionEvent.Experiment?.LayerId)
                                          .WithKey(ACTIVATE_EVENT_KEY)
                                          .WithTimeStamp(impressionEvent.Timestamp)
                                          .Build();

            Snapshot snapshot = new Snapshot(
                new SnapshotEvent[] { snapshotEvent },
                new Decision[] { decision });

            var visitor = new Visitor(new Snapshot[] { snapshot }, impressionEvent.VisitorAttributes, impressionEvent.UserId);

            return(visitor);
        }
コード例 #3
0
        public void TestImpressionEventEqualsSerializedPayload()
        {
            var guid      = Guid.NewGuid();
            var timeStamp = TestData.SecondsSince1970();
            var userId    = "TestUserId";

            var expectedPayload = new Dictionary <string, object>
            {
                { "visitors", new object[]
                  {
                      new Dictionary <string, object>()
                      {
                          { "snapshots", new object[]
                            {
                                new Dictionary <string, object>
                                {
                                    { "decisions", new object[]
                                        {
                                            new Dictionary <string, object>
                                            {
                                                { "campaign_id", "7719770039" },
                                                { "experiment_id", "7716830082" },
                                                { "variation_id", "77210100090" }
                                            }
                                        } },
                                    { "events", new object[]
                                        {
                                            new Dictionary <string, object>
                                            {
                                                { "entity_id", "7719770039" },
                                                { "timestamp", timeStamp },
                                                { "uuid", guid },
                                                { "key", "campaign_activated" }
                                            }
                                        } }
                                }
                            } },
                          { "attributes", new object[]
                            {
                                new Dictionary <string, object>
                                {
                                    { "entity_id", "7723280020" },
                                    { "key", "device_type" },
                                    { "type", "custom" },
                                    { "value", "iPhone" }
                                },
                                new Dictionary <string, object>
                                {
                                    { "entity_id", ControlAttributes.BOT_FILTERING_ATTRIBUTE },
                                    { "key", ControlAttributes.BOT_FILTERING_ATTRIBUTE },
                                    { "type", "custom" },
                                    { "value", true }
                                }
                            } },
                          { "visitor_id", userId }
                      }
                  } },
                { "project_id", "7720880029" },
                { "account_id", "1592310167" },
                { "enrich_decisions", true },
                { "client_name", "csharp-sdk" },
                { "client_version", Optimizely.SDK_VERSION },
                { "revision", "15" },
                { "anonymize_ip", false }
            };

            EventBatch.Builder builder = new EventBatch.Builder();
            builder.WithAccountId("1592310167")
            .WithProjectID("7720880029")
            .WithClientVersion(Optimizely.SDK_VERSION)
            .WithRevision("15")
            .WithClientName("csharp-sdk")
            .WithAnonymizeIP(false)
            .WithEnrichDecisions(true);

            var visitorAttribute1 = new VisitorAttribute(entityId: "7723280020", type: "custom", value: "iPhone", key: "device_type");
            var visitorAttribute2 = new VisitorAttribute(entityId: ControlAttributes.BOT_FILTERING_ATTRIBUTE, type: "custom", value: true, key: ControlAttributes.BOT_FILTERING_ATTRIBUTE);
            var snapshotEvent     = new SnapshotEvent.Builder()
                                    .WithUUID(guid.ToString())
                                    .WithEntityId("7719770039")
                                    .WithKey("campaign_activated")
                                    .WithValue(null)
                                    .WithRevenue(null)
                                    .WithTimeStamp(timeStamp)
                                    .WithEventTags(null)
                                    .Build();

            var decision = new Decision("7719770039", "7716830082", "77210100090");
            var snapshot = new Snapshot(events: new SnapshotEvent[] { snapshotEvent }, decisions: new Decision[] { decision });

            var visitor = new Visitor(
                snapshots: new Snapshot[] {
                snapshot
            },
                attributes: new VisitorAttribute[] {
                visitorAttribute1, visitorAttribute2
            },
                visitorId: "test_user");

            builder.WithVisitors(new Visitor[] { visitor });

            EventBatch eventBatch = builder.Build();

            // Single Conversion Event
            TestData.CompareObjects(expectedPayload, eventBatch);
        }
コード例 #4
0
        public void TestConversionEventEqualsSerializedPayload()
        {
            var guid      = Guid.NewGuid();
            var timeStamp = TestData.SecondsSince1970();

            var expectdPayload = new Dictionary <string, object>
            {
                { "client_version", Optimizely.SDK_VERSION },
                { "project_id", "111001" },
                { "enrich_decisions", true },
                { "account_id", "12001" },
                { "client_name", "csharp-sdk" },
                { "anonymize_ip", false },
                { "revision", "2" },
                { "visitors", new object[]
                  {
                      new Dictionary <string, object>
                      {
                          //visitors[0].attributes
                          {
                              "attributes", new object[]
                              {
                                  new Dictionary <string, string>
                                  {
                                      { "entity_id", "111094" },
                                      { "type", "custom" },
                                      { "value", "test_value" },
                                      { "key", "test_attribute" }
                                  }
                              }
                          },
                          //visitors[0].visitor_id
                          { "visitor_id", "test_user" },
                          //visitors[0].snapshots
                          { "snapshots", new object[]
                            {
                                //snapshots[0]
                                new Dictionary <string, object>
                                {
                                    //snapshots[0].events
                                    {
                                        "events", new object[]
                                        {
                                            new Dictionary <string, object>
                                            {
                                                { "uuid", guid },
                                                { "timestamp", timeStamp },
                                                { "revenue", 4200 },
                                                { "value", 1.234 },
                                                { "key", "event_with_multiple_running_experiments" },
                                                { "entity_id", "111095" },
                                                {
                                                    "tags", new Dictionary <string, object>
                                                    {
                                                        { "non-revenue", "abc" },
                                                        { "revenue", 4200 },
                                                        { "value", 1.234 },
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } }
                      }
                  } }
            };

            EventBatch.Builder builder = new EventBatch.Builder();
            builder.WithAccountId("12001")
            .WithProjectID("111001")
            .WithClientVersion(Optimizely.SDK_VERSION)
            .WithRevision("2")
            .WithClientName("csharp-sdk")
            .WithAnonymizeIP(false)
            .WithEnrichDecisions(true);

            var visitorAttribute = new VisitorAttribute(entityId: "111094", type: "custom", value: "test_value", key: "test_attribute");

            var snapshotEvent = new SnapshotEvent.Builder()
                                .WithUUID(guid.ToString())
                                .WithEntityId("111095")
                                .WithKey("event_with_multiple_running_experiments")
                                .WithValue((long?)1.234)
                                .WithRevenue(4200)
                                .WithTimeStamp(timeStamp)
                                .WithEventTags(new EventTags
            {
                { "non-revenue", "abc" },
                { "revenue", 4200 },
                { "value", 1.234 }
            })
                                .Build();

            var snapshot = new Snapshot(events: new SnapshotEvent[] { snapshotEvent });

            var visitor = new Visitor(
                snapshots: new Snapshot[] {
                snapshot
            },
                attributes: new VisitorAttribute[] {
                visitorAttribute
            },
                visitorId: "test_user");

            builder.WithVisitors(new Visitor[] { visitor });

            EventBatch eventBatch = builder.Build();

            // Single Conversion Event
            TestData.CompareObjects(expectdPayload, eventBatch);
        }