Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: optimizely/php-sdk
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: optimizely/php-sdk
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.6.x
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 7 files changed
  • 1 contributor

Commits on Nov 20, 2020

  1. Copy the full SHA
    29508a9 View commit details
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

11 changes: 6 additions & 5 deletions src/Optimizely/Event/Builder/EventBuilder.php
Original file line number Diff line number Diff line change
@@ -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.
@@ -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 = [
@@ -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
],
]
],
@@ -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;

1 change: 1 addition & 0 deletions src/Optimizely/Event/Builder/Params.php
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
@@ -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;
}
@@ -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) {
@@ -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}'.");
}
15 changes: 13 additions & 2 deletions tests/EventTests/EventBuilderTest.php
Original file line number Diff line number Diff line change
@@ -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,
];
@@ -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
]
]]
);
@@ -146,6 +147,7 @@ public function testCreateImpressionEventNoAttributesNoValue()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
null
);
@@ -205,6 +207,7 @@ public function testCreateImpressionEventWithAttributesNoValue()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
@@ -245,6 +248,7 @@ public function testCreateImpressionEventWithFalseAttributesNoValue()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
@@ -286,6 +290,7 @@ public function testCreateImpressionEventWithZeroAttributesNoValue()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
@@ -317,6 +322,7 @@ public function testCreateImpressionEventWithInvalidAttributesNoValue()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
@@ -357,6 +363,7 @@ public function testCreateImpressionEventWithUserAgentWhenBotFilteringIsEnabled(
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
@@ -404,6 +411,7 @@ public function testCreateImpressionEventWithInvalidAttributeTypes()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
@@ -454,6 +462,7 @@ public function testCreateImpressionEventWithUserAgentWhenBotFilteringIsDisabled
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
@@ -500,6 +509,7 @@ public function testCreateImpressionEventWithUserAgentWhenBotFilteringIsNull()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
@@ -829,6 +839,7 @@ public function testCreateImpressionEventWithBucketingIDAttribute()
'test_experiment',
'test_experiment',
'experiment',
true,
$this->testUserId,
$userAttributes
);
Loading