Skip to content

Commit 009e68c

Browse files
added enabled field in metadata. (#249)
1 parent 780452d commit 009e68c

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

OptimizelySDK.Tests/EventTests/EventFactoryTest.cs

+17-8
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public void TestCreateImpressionEventNoAttributes()
8787
{ "rule_type", "experiment" },
8888
{ "rule_key", "test_experiment" },
8989
{ "flag_key", "test_experiment" },
90-
{ "variation_key", "control" }
90+
{ "variation_key", "control" },
91+
{"enabled", false }
9192
} }
9293
}
9394
}
@@ -168,7 +169,9 @@ public void TestCreateImpressionEventWithAttributes()
168169
{ "rule_type", "experiment" },
169170
{ "rule_key", "test_experiment" },
170171
{ "flag_key", "test_experiment" },
171-
{ "variation_key", "control" }
172+
{ "variation_key", "control" },
173+
{"enabled", false }
174+
172175
}
173176
}
174177
}
@@ -268,7 +271,8 @@ public void TestCreateImpressionEventWithTypedAttributes()
268271
{ "rule_type", "experiment" },
269272
{ "rule_key", "test_experiment" },
270273
{ "flag_key", "test_experiment" },
271-
{ "variation_key", "control" }
274+
{ "variation_key", "control" },
275+
{"enabled", false }
272276
}
273277
}
274278
}
@@ -390,7 +394,8 @@ public void TestCreateImpressionEventRemovesInvalidAttributesFromPayload()
390394
{ "rule_type", "experiment" },
391395
{ "rule_key", "test_experiment" },
392396
{ "flag_key", "test_experiment" },
393-
{ "variation_key", "control" }
397+
{ "variation_key", "control" },
398+
{"enabled", false }
394399
}
395400
}
396401
}
@@ -512,7 +517,8 @@ public void TestCreateImpressionEventRemovesInvalidAttributesFromPayloadRollout(
512517
{ "rule_type", "rollout" },
513518
{ "rule_key", "" },
514519
{ "flag_key", "test_feature" },
515-
{ "variation_key", "" }
520+
{ "variation_key", "" },
521+
{ "enabled", false }
516522
}
517523
}
518524
}
@@ -1526,7 +1532,8 @@ public void TestCreateImpressionEventWithBucketingIDAttribute()
15261532
{ "rule_type", "experiment" },
15271533
{ "rule_key", "test_experiment" },
15281534
{ "flag_key", "test_experiment" },
1529-
{ "variation_key", "control" }
1535+
{ "variation_key", "control" },
1536+
{"enabled", false }
15301537
}
15311538
}
15321539
}
@@ -1633,7 +1640,8 @@ public void TestCreateImpressionEventWhenBotFilteringIsProvidedInDatafile()
16331640
{ "rule_type", "experiment" },
16341641
{ "rule_key", "test_experiment" },
16351642
{ "flag_key", "test_experiment" },
1636-
{ "variation_key", "control" }
1643+
{ "variation_key", "control" },
1644+
{"enabled", false }
16371645
}
16381646
}
16391647
}
@@ -1736,7 +1744,8 @@ public void TestCreateImpressionEventWhenBotFilteringIsNotProvidedInDatafile()
17361744
{ "rule_type", "experiment" },
17371745
{ "rule_key", "test_experiment" },
17381746
{ "flag_key", "test_experiment" },
1739-
{ "variation_key", "control" }
1747+
{ "variation_key", "control" },
1748+
{"enabled", false }
17401749
}
17411750
}
17421751
}

OptimizelySDK/Event/Entity/DecisionMetadata.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ public class DecisionMetadata
3232
public string RuleType { get; private set; }
3333
[JsonProperty("variation_key")]
3434
public string VariationKey { get; private set; }
35+
[JsonProperty("enabled")]
36+
public bool Enabled { get; private set; }
3537

36-
public DecisionMetadata(string flagKey, string ruleKey, string ruleType, string variationKey = "")
38+
public DecisionMetadata(string flagKey, string ruleKey, string ruleType, string variationKey = "", bool enabled = false)
3739
{
3840
FlagKey = flagKey;
3941
RuleKey = ruleKey;
4042
RuleType = ruleType;
4143
VariationKey = variationKey;
44+
Enabled = enabled;
4245
}
4346
}
4447
}

OptimizelySDK/Event/UserEventFactory.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ public static ImpressionEvent CreateImpressionEvent(ProjectConfig projectConfig,
4040
string userId,
4141
UserAttributes userAttributes,
4242
string flagKey,
43-
string ruleType)
43+
string ruleType,
44+
bool enabled = false)
4445
{
4546
Variation variation = projectConfig.GetVariationFromId(activatedExperiment?.Key, variationId);
46-
return CreateImpressionEvent(projectConfig, activatedExperiment, variation, userId, userAttributes, flagKey, ruleType);
47+
return CreateImpressionEvent(projectConfig, activatedExperiment, variation, userId, userAttributes, flagKey, ruleType, enabled);
4748
}
4849

4950
/// <summary>
@@ -63,7 +64,8 @@ public static ImpressionEvent CreateImpressionEvent(ProjectConfig projectConfig,
6364
string userId,
6465
UserAttributes userAttributes,
6566
string flagKey,
66-
string ruleType)
67+
string ruleType,
68+
bool enabled = false)
6769
{
6870
if ((ruleType == FeatureDecision.DECISION_SOURCE_ROLLOUT || variation == null) && !projectConfig.SendFlagDecisions)
6971
{
@@ -84,7 +86,7 @@ public static ImpressionEvent CreateImpressionEvent(ProjectConfig projectConfig,
8486
variationKey = variation.Key;
8587
ruleKey = activatedExperiment.Key;
8688
}
87-
var metadata = new DecisionMetadata(flagKey, ruleKey, ruleType, variationKey);
89+
var metadata = new DecisionMetadata(flagKey, ruleKey, ruleType, variationKey, enabled);
8890

8991
return new ImpressionEvent.Builder()
9092
.WithEventContext(eventContext)

OptimizelySDK/Optimizely.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public Variation Activate(string experimentKey, string userId, UserAttributes us
254254
return null;
255255
}
256256

257-
SendImpressionEvent(experiment, variation, userId, userAttributes, config, SOURCE_TYPE_EXPERIMENT);
257+
SendImpressionEvent(experiment, variation, userId, userAttributes, config, SOURCE_TYPE_EXPERIMENT, true);
258258

259259
return variation;
260260
}
@@ -475,7 +475,6 @@ public virtual bool IsFeatureEnabled(string featureKey, string userId, UserAttri
475475
var variation = decision.Variation;
476476
var decisionSource = decision?.Source ?? FeatureDecision.DECISION_SOURCE_ROLLOUT;
477477

478-
SendImpressionEvent(decision.Experiment, variation, userId, userAttributes, config, featureKey, decisionSource);
479478

480479
if (variation != null)
481480
{
@@ -507,6 +506,8 @@ public virtual bool IsFeatureEnabled(string featureKey, string userId, UserAttri
507506
{ "sourceInfo", sourceInfo },
508507
};
509508

509+
SendImpressionEvent(decision.Experiment, variation, userId, userAttributes, config, featureKey, decisionSource, featureEnabled);
510+
510511
NotificationCenter.SendNotifications(NotificationCenter.NotificationType.Decision, DecisionNotificationTypes.FEATURE, userId,
511512
userAttributes ?? new UserAttributes(), decisionInfo);
512513
return featureEnabled;
@@ -692,9 +693,9 @@ public OptimizelyJSON GetFeatureVariableJSON(string featureKey, string variableK
692693
/// <param name="ruleType">It can either be experiment in case impression event is sent from activate or it's feature-test or rollout</param>
693694
private void SendImpressionEvent(Experiment experiment, Variation variation, string userId,
694695
UserAttributes userAttributes, ProjectConfig config,
695-
string ruleType)
696+
string ruleType, bool enabled)
696697
{
697-
SendImpressionEvent(experiment, variation, userId, userAttributes, config, "", ruleType);
698+
SendImpressionEvent(experiment, variation, userId, userAttributes, config, "", ruleType, enabled);
698699
}
699700

700701
/// <summary>
@@ -708,14 +709,14 @@ private void SendImpressionEvent(Experiment experiment, Variation variation, str
708709
/// <param name="ruleType">It can either be experiment in case impression event is sent from activate or it's feature-test or rollout</param>
709710
private void SendImpressionEvent(Experiment experiment, Variation variation, string userId,
710711
UserAttributes userAttributes, ProjectConfig config,
711-
string flagKey, string ruleType)
712+
string flagKey, string ruleType, bool enabled)
712713
{
713714
if (experiment != null && !experiment.IsExperimentRunning)
714715
{
715716
Logger.Log(LogLevel.ERROR, @"Experiment has ""Launched"" status so not dispatching event during activation.");
716717
}
717718

718-
var userEvent = UserEventFactory.CreateImpressionEvent(config, experiment, variation, userId, userAttributes, flagKey, ruleType);
719+
var userEvent = UserEventFactory.CreateImpressionEvent(config, experiment, variation, userId, userAttributes, flagKey, ruleType, enabled);
719720
if (userEvent == null)
720721
{
721722
return;

0 commit comments

Comments
 (0)