diff --git a/OptimizelySDK.Tests/EventTests/EventBuilderTest.cs b/OptimizelySDK.Tests/EventTests/EventBuilderTest.cs index cd63aa17..d193158f 100644 --- a/OptimizelySDK.Tests/EventTests/EventBuilderTest.cs +++ b/OptimizelySDK.Tests/EventTests/EventBuilderTest.cs @@ -970,6 +970,270 @@ public void TestConversionEventWithNumericTag() Assert.IsTrue(TestData.CompareObjects(expectedEvent, logEvent)); } + [Test] + public void TestConversionEventWithFalsyNumericAndRevenueValues() + { + var guid = Guid.NewGuid(); + var timeStamp = TestData.SecondsSince1970(); + var payloadParams = new Dictionary + { + { "visitors", new object[] + { + new Dictionary() + { + { "snapshots", new object[] + { + new Dictionary + { + { "events", new object[] + { + new Dictionary + { + {"entity_id", "7718020063" }, + {"timestamp", timeStamp }, + {"uuid", guid }, + {"key", "purchase" }, + {"revenue", 0 }, + {"value", 0.0 }, + {"tags", + new Dictionary + { + {"revenue", 0 }, + {"value", 0.0 } + } + } + } + } + } + } + } + }, + { "attributes", new object[] + { + new Dictionary + { + {"entity_id", ControlAttributes.BOT_FILTERING_ATTRIBUTE}, + {"key", ControlAttributes.BOT_FILTERING_ATTRIBUTE}, + {"type", "custom" }, + {"value", true } + } + } + }, + { "visitor_id", TestUserId } + } + } + }, + {"project_id", "7720880029" }, + {"enrich_decisions", true}, + {"account_id", "1592310167" }, + {"client_name", "csharp-sdk" }, + {"client_version", Optimizely.SDK_VERSION }, + {"revision", "15" }, + {"anonymize_ip", false} + }; + + var expectedEvent = new LogEvent( + "https://logx.optimizely.com/v1/events", + payloadParams, + "POST", + new Dictionary + { + { "Content-Type", "application/json"} + }); + + var experimentToVariationMap = new Dictionary + { + {"7716830082", new Variation{Id="7722370027", Key="control"} } + }; + + var logEvent = EventBuilder.CreateConversionEvent(Config, "purchase", TestUserId, null, + new EventTags + { + {"revenue", 0 }, + {"value", 0.0 } + }); + + TestData.ChangeGUIDAndTimeStamp(logEvent.Params, timeStamp, guid); + + Assert.IsTrue(TestData.CompareObjects(expectedEvent, logEvent)); + } + + [Test] + public void TestConversionEventWithNumericValue1() + { + var guid = Guid.NewGuid(); + var timeStamp = TestData.SecondsSince1970(); + var payloadParams = new Dictionary + { + { "visitors", new object[] + { + new Dictionary() + { + { "snapshots", new object[] + { + new Dictionary + { + { "events", new object[] + { + new Dictionary + { + {"entity_id", "7718020063" }, + {"timestamp", timeStamp }, + {"uuid", guid }, + {"key", "purchase" }, + {"revenue", 10 }, + {"value", 1.0 }, + {"tags", + new Dictionary + { + {"revenue", 10 }, + {"value", 1.0 } + } + } + } + } + } + } + } + }, + { "attributes", new object[] + { + new Dictionary + { + {"entity_id", ControlAttributes.BOT_FILTERING_ATTRIBUTE}, + {"key", ControlAttributes.BOT_FILTERING_ATTRIBUTE}, + {"type", "custom" }, + {"value", true } + } + } + }, + { "visitor_id", TestUserId } + } + } + }, + {"project_id", "7720880029" }, + {"enrich_decisions", true}, + {"account_id", "1592310167" }, + {"client_name", "csharp-sdk" }, + {"client_version", Optimizely.SDK_VERSION }, + {"revision", "15" }, + {"anonymize_ip", false} + }; + + var expectedEvent = new LogEvent( + "https://logx.optimizely.com/v1/events", + payloadParams, + "POST", + new Dictionary + { + { "Content-Type", "application/json"} + }); + + var experimentToVariationMap = new Dictionary + { + {"7716830082", new Variation{Id="7722370027", Key="control"} } + }; + + var logEvent = EventBuilder.CreateConversionEvent(Config, "purchase", TestUserId, null, + new EventTags + { + {"revenue", 10 }, + {"value", 1.0 } + }); + + TestData.ChangeGUIDAndTimeStamp(logEvent.Params, timeStamp, guid); + + Assert.IsTrue(TestData.CompareObjects(expectedEvent, logEvent)); + } + [Test] + public void TestConversionEventWithRevenueValue1() + { + var guid = Guid.NewGuid(); + var timeStamp = TestData.SecondsSince1970(); + var payloadParams = new Dictionary + { + { "visitors", new object[] + { + new Dictionary() + { + { "snapshots", new object[] + { + new Dictionary + { + { "events", new object[] + { + new Dictionary + { + {"entity_id", "7718020063" }, + {"timestamp", timeStamp }, + {"uuid", guid }, + {"key", "purchase" }, + {"revenue", 1 }, + {"value", 10.0 }, + {"tags", + new Dictionary + { + {"revenue", 1 }, + {"value", 10.0 } + } + } + } + } + } + } + } + }, + { "attributes", new object[] + { + new Dictionary + { + {"entity_id", ControlAttributes.BOT_FILTERING_ATTRIBUTE}, + {"key", ControlAttributes.BOT_FILTERING_ATTRIBUTE}, + {"type", "custom" }, + {"value", true } + } + } + }, + { "visitor_id", TestUserId } + } + } + }, + {"project_id", "7720880029" }, + {"enrich_decisions", true}, + {"account_id", "1592310167" }, + {"client_name", "csharp-sdk" }, + {"client_version", Optimizely.SDK_VERSION }, + {"revision", "15" }, + {"anonymize_ip", false} + }; + + var expectedEvent = new LogEvent( + "https://logx.optimizely.com/v1/events", + payloadParams, + "POST", + new Dictionary + { + { "Content-Type", "application/json"} + }); + + var experimentToVariationMap = new Dictionary + { + {"7716830082", new Variation{Id="7722370027", Key="control"} } + }; + + var logEvent = EventBuilder.CreateConversionEvent(Config, "purchase", TestUserId, null, + new EventTags + { + {"revenue", 1 }, + {"value", 10.0 } + }); + + TestData.ChangeGUIDAndTimeStamp(logEvent.Params, timeStamp, guid); + + Assert.IsTrue(TestData.CompareObjects(expectedEvent, logEvent)); + } + + [Test] public void TestCreateConversionEventWithBucketingIDAttribute() { diff --git a/OptimizelySDK/Utils/EventTagUtils.cs b/OptimizelySDK/Utils/EventTagUtils.cs index 6b2d1a8f..501ad997 100644 --- a/OptimizelySDK/Utils/EventTagUtils.cs +++ b/OptimizelySDK/Utils/EventTagUtils.cs @@ -92,10 +92,10 @@ public static object GetNumericValue(Dictionary eventTags, ILogg { logMessage = "Provided numeric value is boolean which is an invalid format."; logLevel = LogLevel.ERROR; - } - else if (!(eventTags[VALUE_EVENT_METRIC_NAME] is int) && !(eventTags[VALUE_EVENT_METRIC_NAME] is string) && !(eventTags[VALUE_EVENT_METRIC_NAME] is float) - && !(eventTags[VALUE_EVENT_METRIC_NAME] is decimal) && !(eventTags[VALUE_EVENT_METRIC_NAME] is double) && !(eventTags[VALUE_EVENT_METRIC_NAME] is float)) - { + } else if (!(eventTags[VALUE_EVENT_METRIC_NAME] is int) && !(eventTags[VALUE_EVENT_METRIC_NAME] is string) && !(eventTags[VALUE_EVENT_METRIC_NAME] is float) + && !(eventTags[VALUE_EVENT_METRIC_NAME] is decimal) && !(eventTags[VALUE_EVENT_METRIC_NAME] is double) && !(eventTags[VALUE_EVENT_METRIC_NAME] is long) + && !(eventTags[VALUE_EVENT_METRIC_NAME] is short) && !(eventTags[VALUE_EVENT_METRIC_NAME] is uint)) + { logMessage = "Numeric metric value is not in integer, float, or string form."; logLevel = LogLevel.ERROR; }