Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Optimizely PHP SDK Changelog

## 3.6.1
November 19th, 2020

### Bug Fixes
- Added "enabled" field to decision metadata structure. [#217](https://github.com/optimizely/php-sdk/pull/217)

## 3.6.0
November 2nd, 2020

Expand Down
11 changes: 6 additions & 5 deletions src/Optimizely/Event/Builder/EventBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EventBuilder
/**
* @const string Version of the Optimizely PHP SDK.
*/
const SDK_VERSION = '3.6.0';
const SDK_VERSION = '3.6.1';

/**
* @var string URL to send event to.
Expand Down Expand Up @@ -143,7 +143,7 @@ private function getCommonParams($config, $userId, $attributes)
*
* @return array Hash representing parameters particular to impression event.
*/
private function getImpressionParams(Experiment $experiment, $variation, $flagKey, $ruleKey, $ruleType)
private function getImpressionParams(Experiment $experiment, $variation, $flagKey, $ruleKey, $ruleType, $enabled)
{
$variationKey = $variation->getKey() ? $variation->getKey() : '';
$impressionParams = [
Expand All @@ -156,7 +156,8 @@ private function getImpressionParams(Experiment $experiment, $variation, $flagKe
FLAG_KEY => $flagKey,
RULE_KEY => $ruleKey,
RULE_TYPE => $ruleType,
VARIATION_KEY => $variationKey
VARIATION_KEY => $variationKey,
ENABLED => $enabled
],
]
],
Expand Down Expand Up @@ -228,13 +229,13 @@ private function getConversionParams($eventEntity, $eventTags)
*
* @return LogEvent Event object to be sent to dispatcher.
*/
public function createImpressionEvent($config, $experimentKey, $variationKey, $flagKey, $ruleKey, $ruleType, $userId, $attributes)
public function createImpressionEvent($config, $experimentKey, $variationKey, $flagKey, $ruleKey, $ruleType, $enabled, $userId, $attributes)
{
$eventParams = $this->getCommonParams($config, $userId, $attributes);

$experiment = $config->getExperimentFromKey($experimentKey);
$variation = $config->getVariationFromKey($experimentKey, $variationKey);
$impressionParams = $this->getImpressionParams($experiment, $variation, $flagKey, $ruleKey, $ruleType);
$impressionParams = $this->getImpressionParams($experiment, $variation, $flagKey, $ruleKey, $ruleType, $enabled);

$eventParams[VISITORS][0][SNAPSHOTS][] = $impressionParams;

Expand Down
1 change: 1 addition & 0 deletions src/Optimizely/Event/Builder/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
define('RULE_KEY', 'rule_key');
define('RULE_TYPE', 'rule_type');
define('VARIATION_KEY', 'variation_key');
define('ENABLED', 'enabled');
13 changes: 8 additions & 5 deletions src/Optimizely/Optimizely.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ private function validateUserInputs($attributes, $eventTags = null)
* @param array Associative array of user attributes
* @param DatafileProjectConfig DatafileProjectConfig instance
*/
protected function sendImpressionEvent($config, $experimentKey, $variationKey, $flagKey, $ruleKey, $ruleType, $userId, $attributes)
protected function sendImpressionEvent($config, $experimentKey, $variationKey, $flagKey, $ruleKey, $ruleType, $enabled, $userId, $attributes)
{
$impressionEvent = $this->_eventBuilder
->createImpressionEvent($config, $experimentKey, $variationKey, $flagKey, $ruleKey, $ruleType, $userId, $attributes);
->createImpressionEvent($config, $experimentKey, $variationKey, $flagKey, $ruleKey, $ruleType, $enabled, $userId, $attributes);
$this->_logger->log(Logger::INFO, sprintf('Activating user "%s" in experiment "%s".', $userId, $experimentKey));
$this->_logger->log(
Logger::DEBUG,
Expand Down Expand Up @@ -274,7 +274,7 @@ public function activate($experimentKey, $userId, $attributes = null)
return null;
}

$this->sendImpressionEvent($config, $experimentKey, $variationKey, '', $experimentKey, FeatureDecision::DECITION_SOURCE_EXPERIMENT, $userId, $attributes);
$this->sendImpressionEvent($config, $experimentKey, $variationKey, '', $experimentKey, FeatureDecision::DECITION_SOURCE_EXPERIMENT, true, $userId, $attributes);

return $variationKey;
}
Expand Down Expand Up @@ -556,8 +556,11 @@ public function isFeatureEnabled($featureFlagKey, $userId, $attributes = null)
$variation = $decision->getVariation();

if ($config->getSendFlagDecisions() && ($decision->getSource() == FeatureDecision::DECISION_SOURCE_ROLLOUT || !$variation)) {
if ($variation) {
$featureEnabled = $variation->getFeatureEnabled();
}
$ruleKey = $decision->getExperiment() ? $decision->getExperiment()->getKey() : '';
$this->sendImpressionEvent($config, $ruleKey, $variation ? $variation->getKey() : '', $featureFlagKey, $ruleKey, $decision->getSource(), $userId, $attributes);
$this->sendImpressionEvent($config, $ruleKey, $variation ? $variation->getKey() : '', $featureFlagKey, $ruleKey, $decision->getSource(), $featureEnabled, $userId, $attributes);
}

if ($variation) {
Expand All @@ -569,7 +572,7 @@ public function isFeatureEnabled($featureFlagKey, $userId, $attributes = null)
'variationKey'=> $variation->getKey()
);

$this->sendImpressionEvent($config, $experimentKey, $variation->getKey(), $featureFlagKey, $experimentKey, $decision->getSource(), $userId, $attributes);
$this->sendImpressionEvent($config, $experimentKey, $variation->getKey(), $featureFlagKey, $experimentKey, $decision->getSource(), $featureEnabled, $userId, $attributes);
} else {
$this->_logger->log(Logger::INFO, "The user '{$userId}' is not being experimented on Feature Flag '{$featureFlagKey}'.");
}
Expand Down
15 changes: 13 additions & 2 deletions tests/EventTests/EventBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function setUp()
]],
'revision' => '15',
'client_name' => 'php-sdk',
'client_version' => '3.6.0',
'client_version' => '3.6.1',
'anonymize_ip'=> false,
'enrich_decisions' => true,
];
Expand All @@ -81,7 +81,8 @@ public function setUp()
'flag_key' => 'test_experiment',
'rule_key' => 'test_experiment',
'rule_type' => 'experiment',
'variation_key'=> 'variation'
'variation_key'=> 'variation',
'enabled' => true
]
]]
);
Expand Down Expand Up @@ -146,6 +147,7 @@ public function testCreateImpressionEventNoAttributesNoValue()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
null
);
Expand Down Expand Up @@ -205,6 +207,7 @@ public function testCreateImpressionEventWithAttributesNoValue()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
Expand Down Expand Up @@ -245,6 +248,7 @@ public function testCreateImpressionEventWithFalseAttributesNoValue()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
Expand Down Expand Up @@ -286,6 +290,7 @@ public function testCreateImpressionEventWithZeroAttributesNoValue()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
Expand Down Expand Up @@ -317,6 +322,7 @@ public function testCreateImpressionEventWithInvalidAttributesNoValue()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
Expand Down Expand Up @@ -357,6 +363,7 @@ public function testCreateImpressionEventWithUserAgentWhenBotFilteringIsEnabled(
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
Expand Down Expand Up @@ -404,6 +411,7 @@ public function testCreateImpressionEventWithInvalidAttributeTypes()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
Expand Down Expand Up @@ -454,6 +462,7 @@ public function testCreateImpressionEventWithUserAgentWhenBotFilteringIsDisabled
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
Expand Down Expand Up @@ -500,6 +509,7 @@ public function testCreateImpressionEventWithUserAgentWhenBotFilteringIsNull()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
Expand Down Expand Up @@ -829,6 +839,7 @@ public function testCreateImpressionEventWithBucketingIDAttribute()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
Expand Down
Loading