Skip to content

Fix: SendImpressionEvent will return false when event is not sent #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OptimizelySDK.Tests/OptimizelyUserContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ public void TestDecisionNotification()
var enabled = true;
var variables = Optimizely.GetAllFeatureVariables(flagKey, UserID);
var ruleKey = "test_experiment_with_feature_rollout";
var reasons = new Dictionary<string, object>();
var reasons = new string[] { };
var user = Optimizely.CreateUserContext(UserID);
user.SetAttribute("browser_type", "chrome");

Expand Down
14 changes: 7 additions & 7 deletions OptimizelySDK/Optimizely.cs
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,10 @@ internal OptimizelyDecision Decide(OptimizelyUserContext user,
var decisionSource = flagDecisionResult.ResultObject?.Source ?? FeatureDecision.DECISION_SOURCE_ROLLOUT;
if (!allOptions.Contains(OptimizelyDecideOption.DISABLE_DECISION_EVENT))
{
SendImpressionEvent(flagDecisionResult.ResultObject?.Experiment, variation, userId, userAttributes, config, key, decisionSource, featureEnabled);
decisionEventDispatched = true;
decisionEventDispatched = SendImpressionEvent(flagDecisionResult.ResultObject?.Experiment, variation, userId, userAttributes, config, key, decisionSource, featureEnabled);
}
var decisionReasons = flagDecisionResult.DecisionReasons;
var reasonsToReport = decisionReasons.ToReport(allOptions.Contains(OptimizelyDecideOption.INCLUDE_REASONS));
var reasonsToReport = decisionReasons.ToReport(allOptions.Contains(OptimizelyDecideOption.INCLUDE_REASONS)).ToArray();
var variationKey = flagDecisionResult.ResultObject?.Variation?.Key;

// TODO: add ruleKey values when available later. use a copy of experimentKey until then.
Expand All @@ -828,7 +827,7 @@ internal OptimizelyDecision Decide(OptimizelyUserContext user,
{ "variables", variableMap },
{ "variationKey", variationKey },
{ "ruleKey", ruleKey },
{ "reasons", decisionReasons },
{ "reasons", reasonsToReport },
{ "decisionEventDispatched", decisionEventDispatched }
};

Expand All @@ -842,7 +841,7 @@ internal OptimizelyDecision Decide(OptimizelyUserContext user,
ruleKey,
key,
user,
reasonsToReport.ToArray());
reasonsToReport);
}

internal Dictionary<string, OptimizelyDecision> DecideAll(OptimizelyUserContext user,
Expand Down Expand Up @@ -929,7 +928,7 @@ private void SendImpressionEvent(Experiment experiment, Variation variation, str
/// <param name="userAttributes">The user's attributes</param>
/// <param name="flagKey">It can either be experiment key in case if ruleType is experiment or it's feature key in case ruleType is feature-test or rollout</param>
/// <param name="ruleType">It can either be experiment in case impression event is sent from activate or it's feature-test or rollout</param>
private void SendImpressionEvent(Experiment experiment, Variation variation, string userId,
private bool SendImpressionEvent(Experiment experiment, Variation variation, string userId,
UserAttributes userAttributes, ProjectConfig config,
string flagKey, string ruleType, bool enabled)
{
Expand All @@ -941,7 +940,7 @@ private void SendImpressionEvent(Experiment experiment, Variation variation, str
var userEvent = UserEventFactory.CreateImpressionEvent(config, experiment, variation, userId, userAttributes, flagKey, ruleType, enabled);
if (userEvent == null)
{
return;
return false;
}
EventProcessor.Process(userEvent);

Expand All @@ -958,6 +957,7 @@ private void SendImpressionEvent(Experiment experiment, Variation variation, str
NotificationCenter.SendNotifications(NotificationCenter.NotificationType.Activate, experiment, userId,
userAttributes, variation, impressionEvent);
}
return true;
}

/// <summary>
Expand Down