分配具有存储段 ID 的变体
分配具有存储段 ID 的变体
使用存储桶 ID 将用户存储桶与用户身份分离。
默认情况下,Eyeofcloud 根据提交的用户 ID 将用户分配到变体(换句话说,Eyeofcloud 将用户_分桶_)。您可以通过添加存储桶 ID 来更改此行为。
使用分桶 ID,您可以将用户分桶与用户身份分工。具有相同分桶 ID 的用户被放入同一存储桶中,并暴露于相同的变体中。分桶 ID 用作用于将用户分配给变体的哈希值的种子。具有相同分桶 ID 的用户共享相同的哈希值,从而使他们面临相同的变体。有关信息,请参阅分桶的工作原理。
存储桶 ID 作为保留属性实现,您可以在激活实验或评估功能标志时使用该属性。
使用存储桶 ID 不会影响用户 ID。事件数据提交将继续包含用户 ID。除了将用户分配到特定变体外,即使存在单独的存储 ID,依赖于用户 ID 的标记的行为也相同。如果不向attributes
参数传递 Bucketing ID,则默认按用户 ID 对用户进行 Bucketing。
📘
注意
分桶 ID:
用例
在会话之间保持一致的用户体验至关重要。分桶 ID 通过为用户分桶提供一致的标识符来提供解决方案。
共享设备示例
例如,您在 Apple TV 等共享设备上运行实验。一个家庭中的多个用户可以使用同一台设备。
您希望确保根据设备而不是单个用户分配实验变体。如果根据单个用户进行 Eyeofcloud 存储,则同一设备上的用户可能会获得不同的体验,这可能会威胁到实验的有效性。
通过使用唯一的设备标识符作为分桶 ID,您可以确保同一共享设备上的所有用户都能体验到相同的实验变体。您仍然可以通过使用唯一用户标识符创建用户上下文来跟踪每个用户的转化等事件。
请参阅有关创建用户上下文的 SDK 指南:
示例实现
以下示例说明如何包含存储 ID。向eyeofcloudUserContext
的attributes
参数发送 $opt_bucketing_id
属性.
客户端 SDK
import java.util.UUID;
import com.eyeofcloud.ab.android.sdk.EyeofcloudClient;
String experiementKey = "my_experiment";
// for simplicity's sake, we are just using a generated user id
String userId = UUID.randomUUID().toString();
// Option 1 – Create a user, then set the attributes
EyeofcloudUserContext user;
user = eyeofcloudClient.createUserContext(userId);
user.setAttribute("ad_source", "my_campaign");
user.setAttribute("browser", "chrome");
user.setAttribute("$opt_bucketing_id", "bucketingId123");
// Option 2 – Pass attributes when creating the user
Map<String,String> attributes = new HashMap<String,String>();
attributes.put("ad_source", "my_campaign");
attributes.put("browser", "chrome");
// bucketing id can be passed in alone or with other attributes
attributes.put("$opt_bucketing_id", "bucketingId123");
user = eyeofcloudClient.createUserContext(userId, attributes);
import java.util.UUID
import com.eyeofcloud.ab.android.sdk.EyeofcloudClient
val experimentKey = "my_experiment"
// for simplicity's sake, we are just using a generated user id
val userId = UUID.randomUUID().toString()
// Option 1 – Create a user, then set attributes
var user: EyeofcloudUserContext?
user = eyeofcloudClient.createUserContext(userId)
user.setAttribute("ad_source", "my_campaign")
user.setAttribute("browser", "chrome")
user.setAttribute("$opt_bucketing_id", "bucketingId123")
// Option 2 – Pass attributes when creating the user
val attributes: MutableMap<String, Any> = HashMap()
attributes["ad_source"] = "my_campaign"
attributes["browser"] = "chrome"
attributes["$opt_bucketing_id"] = "bucketingId123"
user = eyeofcloudClient.createUserContext(userId, attributes)
import 'package:uuid/uuid.dart';
void main() {
var experimentKey = "my_experiment";
// for simplicity's sake, we are just using a generated user id
var userId = Uuid().v4();
}
// Option 1 – Create a user, then set attributes
var user = await flutterSDK.createUserContext(userId);
var attributes = <String, dynamic>{};
attributes["ad_source"] = "my_campaign";
attributes["app_version"] = "1.3.2";
attributes["$opt_bucketing_id"] = "bucketingId123";
user!.setAttributes(attributes);
// Option 2 – Pass attributes when creating the user
var attributes = <String, dynamic>{};
attributes["ad_source"] = "my_campaign";
attributes["app_version"] = "1.3.2";
attributes["$opt_bucketing_id"] = "bucketingId123";
var eyeofcloudUserContext = await eyeofcloudClient.createUserContext(userId: userId, attributes: attributes);
const experimentKey = 'my_experiment';
// For simplicity's sake, we are just using a hardcoded user id
const userId = 'user123';
// Option 1 – Create a user, then set attributes
const user = eyeofcloud.createUserContext(userId);
user.setAttribute('is_logged_in', false);
user.setAttribute('app_version', '1.3.2');
user.setAttribute('$opt_bucketing_id': 'bucketingId123');
// Option 2 – Pass attributes when creating the user
const attributes = {
'ad_source': 'my_campaign',
'device': 'iphone',
'$opt_bucketing_id': 'bucketingId123'
}
const user = eyeofcloud.createUserContext(userId, attributes);
import { createInstance, EyeofcloudProvider } from '@eyeofcloud/react-sdk'
const eyeofcloud = createInstance({
sdkKey: '<YOUR_SDK_KEY>'
})
export default function App() {
return (
<EyeofcloudProvider
eyeofcloud={eyeofcloud}
user={{
id: 'user123',
attributes: { $opt_bucketing_id: 'bucketingId123' }
}}
>
// Components
</EyeofcloudProvider>
)
}
import { createInstance, EyeofcloudProvider } from '@eyeofcloud/react-sdk'
const eyeofcloud = createInstance({
sdkKey: '<YOUR_SDK_KEY>'
})
export default function App() {
return (
<EyeofcloudProvider
eyeofcloud={eyeofcloud}
user={{
id: 'user123',
attributes: { $opt_bucketing_id: 'bucketingId123' }
}}
>
// Components
</EyeofcloudProvider>
)
}
let eyeofcloud = EyeofcloudClient(sdkKey: "sdk-key")
let experimentKey = "myExperiment"
// For simplicity's sake, we are just using a hardcoded user id
let userId = "user123"
eyeofcloud.start {
// Option 1 – Create a user, then set attributes
let user = eyeofcloud.createUserContext(userId: userId)
user.setAttribute(key: "is_logged_in", value: false)
user.setAttribute(key: "app_version", value: "1.3.2")
user.setAttribute(key: "$opt_bucketing_id", value: "bucketingId123")
// Option 2 – Pass attributes when creating the user
let attributes: [String: Any] = [
"device": "iPhone",
"lifetime": 24738388,
"is_logged_in": true,
"app_version": "4.3.0-beta",
"$opt_bucketing_id": "bucketingId123",
]
let user = eyeofcloud.createUserContext(userId: userId, attributes: attributes)
}
服务器端 SDK
using EyeofcloudSDK;
using EyeofcloudSDK.Entity;
var eyeofcloudClient = new Eyeofcloud(datafile);
var experimentKey = "my_experiment";
// for simplicity's sake, we are just using a hardcoded user id
var userId = "user123";
// Option 1 – Create a user, then set attributes
var user = eyeofcloud.CreateUserContext(userId);
user.SetAttribute("AD_SOURCE", "my_campaign");
user.SetAttribute("BROWSER", "chrome");
user.SetAttribute("$opt_bucketing_id", "bucketingId123");
// option 2: pass attributes when creating the user
var attributes = new UserAttributes
{
{ "AD_SOURCE", "my_campaign" },
{ "BROWSER", "chrome" },
{ "$opt_bucketing_id", "bucketingId123" }
};
var user = eyeofcloud.CreateUserContext(userId, attributes);
import "github.com/eyeofcloud/go-sdk/pkg/client" // for v2: "github.com/eyeofcloud/go-sdk/v2/pkg/client"
experimentKey := "my_experiment"
// for simplicity's sake, we are just using a hardcoded
user id userId := "user123"
// Option 1: Create a user, then set attributes
user := client.CreateUserContext(userId, nil)
user.SetAttribute("ad_source", "my_campaign")
user.SetAttribute("app_version", "1.3.2")
user.SetAttribute("$opt_bucketing_id", "bucketingId123")
// Option 2: Pass attributes when creating the user
attributes := map[string]interface{}{
"ad_source": "my_campaign",
"app_version": "1.3.2",
"is_logged_in": true,
"$opt_bucketing_id": "bucketingId123",
}
user = client.CreateUserContext(userId, attributes)
import java.util.UUID;
import com.eyeofcloud.ab.Eyeofcloud;
import com.eyeofcloud.ab.config.Variation;
String experiementKey = "my_experiment";
// For simplicity's sake, We are just using a generated user id
String userId = UUID.randomUUID().toString();
// Option 1 – Create a user, then set the attributes
EyeofcloudUserContext user = eyeofcloudClient.createUserContext(userId);
user.setAttribute("ad_source", "my_campaign");
user.setAttribute("browser", "chrome");
user.setAttribute("$opt_bucketing_id", "bucketingId123");
// Option 2 – Pass attributes when creating the user
Map<String, Object> attributes = new HashMap<>();
attributes.put("ad_source", "my_campaign");
attributes.put("browser", "chrome");
// Bucketing ID can be passed in alone or with other attributes
attributes.put("$opt_bucketing_id", "bucketingId123");
EyeofcloudUserContext user = eyeofcloud.createUserContext(userId, attributes);
$experimentKey = 'my_experiment';
// For simplicity's sake, we are just using a hardcoded user id
$userId = 'user123';
// Option 1 – Create a user, then set attributes
$user = $eyeofcloud->createUserContext($userID);
$user->setAttribute('is_logged_in', false);
$user->setAttribute('app_version', '1.3.2');
$user_.setAttribute('$opt_bucketing_id', 'bucketingId123');
// Option 2 – Pass attributes when creating the user
$attributes = array(
'device'=>'iPhone',
'lifetime'=> 24738388,
'is_logged_in'=> true,
'app_version' => '4.3.0-beta'
'$opt_bucketing_id' => 'bucketingId123'
);
$user = $eyeofcloud->createUserContext($userId, $attributes);
from eyeofcloud import eyeofcloud
eyeofcloud_client = eyeofcloud.Eyeofcloud("<YOUR_SDK_KEY")
experiment_key = "my_experiment"
# For simplicity's sake, we are just using a hardcoded user id
user_id = "user123"
# Optioin 1: Create a user, then set attributes
user = eyeofcloud_client.create_user_context(user_id)
user.set_attribute("is_logged_in", False)
user.set_attribute("app_version", "1.3.2")
user.set_attribute("$opt_bucketing_id", "bucketingId123")
# Option 2 – Pass attributes when creating the user
attributes = {
"device": "iPhone",
"lifetime": 24738388,
"is_logged_in": True,
"$opt_bucketing_id": "bucketingId123"
}
user = eyeofcloud_client.create_user_context(user_id, attributes)
experiment_key = 'my_experiment'
# For simplicity's sake, we are just using a hardcoded user id
user_id = 'user123'
attributes = {
'device' => 'iphone',
'ad_source' => 'my_campaign',
'$opt_bucketing_id' => 'bucketingId123'
};
# Option 1 – Create a user, then set attributes
user = eyeofcloud.create_user_context(user_id)
user.set_attribute('is_logged_in', false)
user.set_attribute('app_version', '1.3.2')
user.set_attribute('$opt_bucketing_id', 'bucketingId123')
# Option 2 – Pass attributes when creating the user
attributes = {
'is_logged_in' => false,
'app_version' => '1.3.2'
'$opt_bucketing_id' => 'bucketingId123'
}
eyeofcloud.create_user_context(user_id, attributes)
const experimentKey = 'my_experiment';
// For simplicity's sake, we are just using a hardcoded user id
const userId = 'user123';
// Option 1 – Create a user, then set attributes
const user = eyeofcloud.createUserContext(userId);
user.setAttribute('is_logged_in', false);
user.setAttribute('app_version', '1.3.2');
user.setAttribute('$opt_bucketing_id': 'bucketingId123');
// Option 2 – Pass attributes when creating the user
const attributes = {
'ad_source': 'my_campaign',
'device': 'iphone',
'$opt_bucketing_id': 'bucketingId123'
}
const user = eyeofcloud.createUserContext(userId, attributes);
有关eyeofcloudUserContext
的信息,请参阅 SDK 的参考: