Skip to content

Commit dc860a9

Browse files
msohailhussainmikeproeng37
authored andcommitted
fix(eventtagsutils) : don't exclude falsy values (#132)
1 parent 8d4d2dc commit dc860a9

File tree

2 files changed

+268
-4
lines changed

2 files changed

+268
-4
lines changed

OptimizelySDK.Tests/EventTests/EventBuilderTest.cs

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,270 @@ public void TestConversionEventWithNumericTag()
970970
Assert.IsTrue(TestData.CompareObjects(expectedEvent, logEvent));
971971
}
972972

973+
[Test]
974+
public void TestConversionEventWithFalsyNumericAndRevenueValues()
975+
{
976+
var guid = Guid.NewGuid();
977+
var timeStamp = TestData.SecondsSince1970();
978+
var payloadParams = new Dictionary<string, object>
979+
{
980+
{ "visitors", new object[]
981+
{
982+
new Dictionary<string, object>()
983+
{
984+
{ "snapshots", new object[]
985+
{
986+
new Dictionary<string, object>
987+
{
988+
{ "events", new object[]
989+
{
990+
new Dictionary<string, object>
991+
{
992+
{"entity_id", "7718020063" },
993+
{"timestamp", timeStamp },
994+
{"uuid", guid },
995+
{"key", "purchase" },
996+
{"revenue", 0 },
997+
{"value", 0.0 },
998+
{"tags",
999+
new Dictionary<string, object>
1000+
{
1001+
{"revenue", 0 },
1002+
{"value", 0.0 }
1003+
}
1004+
}
1005+
}
1006+
}
1007+
}
1008+
}
1009+
}
1010+
},
1011+
{ "attributes", new object[]
1012+
{
1013+
new Dictionary<string, object>
1014+
{
1015+
{"entity_id", ControlAttributes.BOT_FILTERING_ATTRIBUTE},
1016+
{"key", ControlAttributes.BOT_FILTERING_ATTRIBUTE},
1017+
{"type", "custom" },
1018+
{"value", true }
1019+
}
1020+
}
1021+
},
1022+
{ "visitor_id", TestUserId }
1023+
}
1024+
}
1025+
},
1026+
{"project_id", "7720880029" },
1027+
{"enrich_decisions", true},
1028+
{"account_id", "1592310167" },
1029+
{"client_name", "csharp-sdk" },
1030+
{"client_version", Optimizely.SDK_VERSION },
1031+
{"revision", "15" },
1032+
{"anonymize_ip", false}
1033+
};
1034+
1035+
var expectedEvent = new LogEvent(
1036+
"https://logx.optimizely.com/v1/events",
1037+
payloadParams,
1038+
"POST",
1039+
new Dictionary<string, string>
1040+
{
1041+
{ "Content-Type", "application/json"}
1042+
});
1043+
1044+
var experimentToVariationMap = new Dictionary<string, Variation>
1045+
{
1046+
{"7716830082", new Variation{Id="7722370027", Key="control"} }
1047+
};
1048+
1049+
var logEvent = EventBuilder.CreateConversionEvent(Config, "purchase", TestUserId, null,
1050+
new EventTags
1051+
{
1052+
{"revenue", 0 },
1053+
{"value", 0.0 }
1054+
});
1055+
1056+
TestData.ChangeGUIDAndTimeStamp(logEvent.Params, timeStamp, guid);
1057+
1058+
Assert.IsTrue(TestData.CompareObjects(expectedEvent, logEvent));
1059+
}
1060+
1061+
[Test]
1062+
public void TestConversionEventWithNumericValue1()
1063+
{
1064+
var guid = Guid.NewGuid();
1065+
var timeStamp = TestData.SecondsSince1970();
1066+
var payloadParams = new Dictionary<string, object>
1067+
{
1068+
{ "visitors", new object[]
1069+
{
1070+
new Dictionary<string, object>()
1071+
{
1072+
{ "snapshots", new object[]
1073+
{
1074+
new Dictionary<string, object>
1075+
{
1076+
{ "events", new object[]
1077+
{
1078+
new Dictionary<string, object>
1079+
{
1080+
{"entity_id", "7718020063" },
1081+
{"timestamp", timeStamp },
1082+
{"uuid", guid },
1083+
{"key", "purchase" },
1084+
{"revenue", 10 },
1085+
{"value", 1.0 },
1086+
{"tags",
1087+
new Dictionary<string, object>
1088+
{
1089+
{"revenue", 10 },
1090+
{"value", 1.0 }
1091+
}
1092+
}
1093+
}
1094+
}
1095+
}
1096+
}
1097+
}
1098+
},
1099+
{ "attributes", new object[]
1100+
{
1101+
new Dictionary<string, object>
1102+
{
1103+
{"entity_id", ControlAttributes.BOT_FILTERING_ATTRIBUTE},
1104+
{"key", ControlAttributes.BOT_FILTERING_ATTRIBUTE},
1105+
{"type", "custom" },
1106+
{"value", true }
1107+
}
1108+
}
1109+
},
1110+
{ "visitor_id", TestUserId }
1111+
}
1112+
}
1113+
},
1114+
{"project_id", "7720880029" },
1115+
{"enrich_decisions", true},
1116+
{"account_id", "1592310167" },
1117+
{"client_name", "csharp-sdk" },
1118+
{"client_version", Optimizely.SDK_VERSION },
1119+
{"revision", "15" },
1120+
{"anonymize_ip", false}
1121+
};
1122+
1123+
var expectedEvent = new LogEvent(
1124+
"https://logx.optimizely.com/v1/events",
1125+
payloadParams,
1126+
"POST",
1127+
new Dictionary<string, string>
1128+
{
1129+
{ "Content-Type", "application/json"}
1130+
});
1131+
1132+
var experimentToVariationMap = new Dictionary<string, Variation>
1133+
{
1134+
{"7716830082", new Variation{Id="7722370027", Key="control"} }
1135+
};
1136+
1137+
var logEvent = EventBuilder.CreateConversionEvent(Config, "purchase", TestUserId, null,
1138+
new EventTags
1139+
{
1140+
{"revenue", 10 },
1141+
{"value", 1.0 }
1142+
});
1143+
1144+
TestData.ChangeGUIDAndTimeStamp(logEvent.Params, timeStamp, guid);
1145+
1146+
Assert.IsTrue(TestData.CompareObjects(expectedEvent, logEvent));
1147+
}
1148+
[Test]
1149+
public void TestConversionEventWithRevenueValue1()
1150+
{
1151+
var guid = Guid.NewGuid();
1152+
var timeStamp = TestData.SecondsSince1970();
1153+
var payloadParams = new Dictionary<string, object>
1154+
{
1155+
{ "visitors", new object[]
1156+
{
1157+
new Dictionary<string, object>()
1158+
{
1159+
{ "snapshots", new object[]
1160+
{
1161+
new Dictionary<string, object>
1162+
{
1163+
{ "events", new object[]
1164+
{
1165+
new Dictionary<string, object>
1166+
{
1167+
{"entity_id", "7718020063" },
1168+
{"timestamp", timeStamp },
1169+
{"uuid", guid },
1170+
{"key", "purchase" },
1171+
{"revenue", 1 },
1172+
{"value", 10.0 },
1173+
{"tags",
1174+
new Dictionary<string, object>
1175+
{
1176+
{"revenue", 1 },
1177+
{"value", 10.0 }
1178+
}
1179+
}
1180+
}
1181+
}
1182+
}
1183+
}
1184+
}
1185+
},
1186+
{ "attributes", new object[]
1187+
{
1188+
new Dictionary<string, object>
1189+
{
1190+
{"entity_id", ControlAttributes.BOT_FILTERING_ATTRIBUTE},
1191+
{"key", ControlAttributes.BOT_FILTERING_ATTRIBUTE},
1192+
{"type", "custom" },
1193+
{"value", true }
1194+
}
1195+
}
1196+
},
1197+
{ "visitor_id", TestUserId }
1198+
}
1199+
}
1200+
},
1201+
{"project_id", "7720880029" },
1202+
{"enrich_decisions", true},
1203+
{"account_id", "1592310167" },
1204+
{"client_name", "csharp-sdk" },
1205+
{"client_version", Optimizely.SDK_VERSION },
1206+
{"revision", "15" },
1207+
{"anonymize_ip", false}
1208+
};
1209+
1210+
var expectedEvent = new LogEvent(
1211+
"https://logx.optimizely.com/v1/events",
1212+
payloadParams,
1213+
"POST",
1214+
new Dictionary<string, string>
1215+
{
1216+
{ "Content-Type", "application/json"}
1217+
});
1218+
1219+
var experimentToVariationMap = new Dictionary<string, Variation>
1220+
{
1221+
{"7716830082", new Variation{Id="7722370027", Key="control"} }
1222+
};
1223+
1224+
var logEvent = EventBuilder.CreateConversionEvent(Config, "purchase", TestUserId, null,
1225+
new EventTags
1226+
{
1227+
{"revenue", 1 },
1228+
{"value", 10.0 }
1229+
});
1230+
1231+
TestData.ChangeGUIDAndTimeStamp(logEvent.Params, timeStamp, guid);
1232+
1233+
Assert.IsTrue(TestData.CompareObjects(expectedEvent, logEvent));
1234+
}
1235+
1236+
9731237
[Test]
9741238
public void TestCreateConversionEventWithBucketingIDAttribute()
9751239
{

OptimizelySDK/Utils/EventTagUtils.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ public static object GetNumericValue(Dictionary<string, object> eventTags, ILogg
9292
{
9393
logMessage = "Provided numeric value is boolean which is an invalid format.";
9494
logLevel = LogLevel.ERROR;
95-
}
96-
else if (!(eventTags[VALUE_EVENT_METRIC_NAME] is int) && !(eventTags[VALUE_EVENT_METRIC_NAME] is string) && !(eventTags[VALUE_EVENT_METRIC_NAME] is float)
97-
&& !(eventTags[VALUE_EVENT_METRIC_NAME] is decimal) && !(eventTags[VALUE_EVENT_METRIC_NAME] is double) && !(eventTags[VALUE_EVENT_METRIC_NAME] is float))
98-
{
95+
} else if (!(eventTags[VALUE_EVENT_METRIC_NAME] is int) && !(eventTags[VALUE_EVENT_METRIC_NAME] is string) && !(eventTags[VALUE_EVENT_METRIC_NAME] is float)
96+
&& !(eventTags[VALUE_EVENT_METRIC_NAME] is decimal) && !(eventTags[VALUE_EVENT_METRIC_NAME] is double) && !(eventTags[VALUE_EVENT_METRIC_NAME] is long)
97+
&& !(eventTags[VALUE_EVENT_METRIC_NAME] is short) && !(eventTags[VALUE_EVENT_METRIC_NAME] is uint))
98+
{
9999
logMessage = "Numeric metric value is not in integer, float, or string form.";
100100
logLevel = LogLevel.ERROR;
101101
}

0 commit comments

Comments
 (0)