User Module
This page explains how to integrate the Playol SDK user system, retrieve platform-injected user data, listen for changes, and properly manage player identity and data binding.
The Playol SDK includes a robust built-in user module that allows developers to obtain platform-level identity, avatar, nickname, and user type without building their own registration or login system. This user identity is automatically linked to game data such as save progress, items, leaderboards, and more.
📌 1. User Info Structure
After the Playol SDK is initialized, user data will be automatically injected and mounted to window.playolSDK.user.userInfo. The structure is as follows:
| Field | Type | Description |
|---|---|---|
userId | string | Unique user ID (generated by platform, globally unique) |
userName | string | User nickname (may be empty, fallback handling recommended) |
avatar | string | User avatar URL, can be used for display |
sex | number | Gender: 0 = Male, 1 = Female, 2 = Unknown |
userType | number | User type: 0 = Guest, 1 = Registered |
Example:
{
"userId": "231175897226391552",
"userName": "QEkuj",
"sex": 0,
"avatar": "https://static.playol.com/upload/userAvatarCover/avatar_1.png",
"userType": 1
}⚠️ Note: Some fields may be empty or use default values. Always implement proper fallback handling in UI rendering.
📥 2. How to Get User Info
As part of the game runtime environment, Playol SDK provides two methods for accessing the current player’s data:
✅ Method 1: Read Cached Variable
const userInfo = window.playolSDK.user.userInfo
console.log(userInfo)- This variable is automatically populated after SDK loads;
- It also updates in real-time when the platform user changes.
✅ Method 2: Fetch Latest Data Asynchronously
// Promise style
window.playolSDK.user.getUserInfo().then(userInfo => {
console.log(userInfo)
})
// Async/Await style
const userInfo = await window.playolSDK.user.getUserInfo()
console.log(userInfo)- Retrieves the latest user info from the platform;
- The result also updates the cached
user.userInfovariable.
📡 3. Listen for User Info Changes
When users switch accounts, log out, or their identity changes, the SDK will automatically trigger any registered listeners:
const handleUserChange = (userInfo) => {
console.log("User info updated:", userInfo)
}
// Add listener
window.playolSDK.user.onChange(handleUserChange)
// Remove listener
window.playolSDK.user.removeChange(handleUserChange)✅ It is recommended to register listeners after the game is fully loaded. If your game has multiple scenes or “re-enter” logic, be sure to call
removeChange()at the appropriate time to avoid memory leaks or state conflicts.
🧾 4. User Type Explanation
| userType | Description | Permissions |
|---|---|---|
0 | Guest | Can try the game, but cannot make payments or sync assets |
1 | Registered User | Full access to payments, ads, data sync, leaderboard, etc. |
⚠️ Guest users can be guided to register through the platform. The SDK will support upgrade logic in future versions.
🛠️ 5. Recommended Use Cases
| Scenario | Recommended Action |
|---|---|
| Game first launch | Use getUserInfo() to fetch and cache user identity |
| Displaying user name/avatar | Use user.userInfo.userName and avatar fields |
| Bind data/items to user | Use userId as player key |
| Cross-device sync | userId is globally unique and consistent |
| Multi-instance / iframe mode | Use onChange() to detect identity changes |
| Detect guest mode | Check user.userInfo.userType === 0 |
📦 6. FAQ
Q: userInfo is undefined or empty?
A: Ensure the SDK has been loaded and initSDKParam() is executed before accessing user info. Prefer getUserInfo() for a reliable fetch.
Q: Can guest users use ads or payment?
A: Not recommended. The platform may restrict such features for guest accounts. Guide users to register before using advanced features.
Q: Can users switch accounts?
A: Yes. The platform supports account switching. The SDK will automatically trigger the registered change listeners—no additional handling required.
🔗 Related Docs
👉 Quick Start | Payment Module | Data Module | Invite Module