Skip to content

Commit

Permalink
Merge pull request #70 from statsig-io/allocated-experiment
Browse files Browse the repository at this point in the history
Add Allocated Experiment For Layers
  • Loading branch information
sroyal-statsig committed Mar 13, 2024
2 parents 10240d8 + 86b27d5 commit 6b392de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Layer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ class Layer
private string $rule_id;
private \Closure $exposure_log_fn;
private ?string $group_name;
private ?string $allocated_experiment_name;

function __construct(string $name, array $value = [], string $rule_id = "", ?callable $exposure_log_fn = null, ?string $group_name = null)
function __construct(string $name, array $value = [], string $rule_id = "", ?callable $exposure_log_fn = null, ?string $group_name = null, ?string $allocated_experiment_name = null)
{
$this->name = $name;
$this->rule_id = $rule_id;
$exposure_log_fn = $exposure_log_fn ?? function () {};
$this->exposure_log_fn = \Closure::fromCallable($exposure_log_fn);
$this->group_name = $group_name;
$this->allocated_experiment_name = $allocated_experiment_name;

// We re-decode here to treat associative arrays as objects, this allows us
// to differentiate between array ([1,2]) and object (['a' => 'b'])
Expand Down Expand Up @@ -72,4 +74,9 @@ function getGroupName(): ?string
{
return $this->group_name;
}

function getAllocatedExperimentName(): ?string
{
return $this->allocated_experiment_name;
}
}
2 changes: 1 addition & 1 deletion src/StatsigServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function getLayer(StatsigUser $user, string $layer): Layer
$res,
);
};
return new Layer($layer, $json_value, $rule_id, $log_exposure_fn, $res->group_name);
return new Layer($layer, $json_value, $rule_id, $log_exposure_fn, $res->group_name, $res->allocated_experiment == "" ? null : $res->allocated_experiment);
};
$fallback = function () use ($layer) {
return new Layer($layer);
Expand Down

0 comments on commit 6b392de

Please sign in to comment.