There are a few ways you can do this depending on the use case. The full API signature of isFeatureEnabled
is the following:
isFeatureEnabled(feature_key, userId, attributes)
where in general:
isFeatureEnabled(
'my_feature', // feature key identifier linking feature to Optimizely UI
'123', // userId parameter used as input to random bucketing
{ 'organizationId': '789' } // attributes used for non-random targeting
)
--
Use Case 1: If you want to manually select one-by-one which organization gets the feature enabled, you should use audience targeting via attributes.
You can pass in the organizationId as an attribute and setup an audience to target all visitors that are in that organization.
isFeatureEnabled('my_feature', '123', { organizationId: '789' } ); // User 123
isFeatureEnabled('my_feature', '456', { organizationId: '789' } ); // User 456
For instructions on how to setup the attributes and audiences in the Optimizely UI for this use case, follow this documentation article.
Using attributes and audiences allows you to enable or disable a feature for specific organizations one-by-one. However, this approach does not allow you to randomly rollout to a percentage of the possible organizationIds or do an A/B test on a random sampling of organizationIds.
--
Use Case 2: If you want to run rollout to a random sampling of organizationIds or run an A/B test where a random set of organizations get a particular experience you should pass in the organizationId as the userId parameter to the isFeatureEnabled API:
isFeatureEnabled('my_feature', '789'); // User 123
isFeatureEnabled('my_feature', '789'); // User 456
The userId parameter to isFeatureEnabled
is used to randomly bucket the user. Since the userId can accept any string, using the organizationId in this case ensures that both user 123 and 456 will get bucketed into the same experience.
--
Use Case 3: If you want to be able to both run an A/B test across organizations but also have the ability to target only certain organizations, you should combine the methods of the two uses above like the following:
isFeatureEnabled('my_feature', '789', { companyId: '789' } ); // User 123
isFeatureEnabled('my_feature', '789', { companyId: '789' } ); // User 456
This way allows you to manually (rather than randomly) select one-by-one which customer should see an experience or be eligible for an experiment while also allowing you to rollout randomly across organizations or run an A/B test across organizations.