GSM Users

Là các tính năng liên quan đến user

Trong GSM Users có các chức năng sau:

  1. Set Properties: Dùng để cập nhật thông tin user.

  2. Get Properties: Dùng để lấy các thông tin user đã được lưu trữ.

  3. Chức năng Invite: Dùng để user A đi chia sẻ game cho user B cài đặt và nhận thưởng.

1. Set Properties

  • Dùng để cập nhật thông tin user, phục vụ cho việc phân tích hành vi user.

  • Tùy từng logic của game mà sẽ cập nhật các property tùy theo các trường hợp. Ví dụ: Khi có thay đổi về avatar, name, userType thì sẽ cập nhật luôn thông tin user.

 void SetUserProperties(params Property[] properties)

Các tham số

  • properties: Mảng các thuộc tính của user

Hoặc:

void SetUserProperties(Dictionary<string, object> parameters)

Các tham số

  • parameters: Là một dictionary chứa các thuộc tính của user

Code mẫu:

GSM.Users.GSMUser.SetUserProperties(new GSM.Models.Property[]
{
    new GSM.Models.Property(GSM.Models.PropertyPreset.name, "Sample"), // Thường thay đổi khi user đổi tên (tùy chọn)
    new GSM.Models.Property(GSM.Models.PropertyPreset.avatar, "1"), // avatar id có sẵn trong game (tùy chọn)
    new GSM.Models.Property(GSM.Models.PropertyPreset.facebookId, ""), // Khi đăng nhập bằng facebook (tùy chọn)
    new GSM.Models.Property(GSM.Models.PropertyPreset.email, "tuyennv@cscmobi.com"), // Khi đăng nhập bằng email (tùy chọn)
    new GSM.Models.Property(GSM.Models.PropertyPreset.firebaseId, "TslbnCoZ0DRzqEjxNRwSpqkFp0B2"), // Khi đồng bộ tiến trình game lên realtimeDatabase/Firestore của Firebase (nếu có tính năng lưu tiến trình thì bắt buộc)
    new GSM.Models.Property(GSM.Models.PropertyPreset.lang, "vi"), // Thường thay đổi trong phần đổi ngôn ngữ 
    new GSM.Models.Property(GSM.Models.PropertyPreset.userType, "2"), //Khi thay đổi userType (tùy chọn)
    new GSM.Models.Property(GSM.Models.PropertyPreset.scene, "Splash"), //Track màn hình user đang tương tác (bắt buộc)
    new GSM.Models.Property(GSM.Models.PropertyPreset.deviceName, "Iphone 12 Pro Max")
});

1.1 Set FCM Token

  • FCM Token là token được firebase trả lại khi tích hợp Firebase Cloud Messaging

  • Mục đích để server sẽ gửi remote notification về device thông qua token này.

  • Thông thường chỉ khi lần đầu tiên mở game, hoặc có thay đổi về token thì sẽ thực hiện chức năng này.

Code mẫu:

Firebase.Messaging.FirebaseMessaging.GetTokenAsync().ContinueWithOnMainThread(task =>
{
    //Lấy fcmToken từ Firebase
    string fcmToken=task.Result;
    //Update property fcmToken lên GSM
    GSM.Users.GSMUser.SetUserProperties(new GSM.Models.Property[]
    {
        new GSM.Models.Property(GSM.Models.PropertyPreset.fcmToken, fcmToken)
    });
});

1.2 Set UserType

  • Dùng để phân loại user, tùy từng game mà userType có các mức phân loại user khác nhau.

Code mẫu:

GSM.Users.GSMUser.SetUserProperties(new GSM.Models.Property[]
{
    new GSM.Models.Property(GSM.Models.PropertyPreset.userType, "2")
});

2. Get Properties

  • Dùng để lấy các thuộc tính đã set của user

  • Có thể lấy 1 hoặc nhiều thuộc tính tùy ý.

void GetProperties(PropertyPreset[] fields, Action<string> onSuccess, Action<long, string> errorCallBack = null)

Các tham số

  • fields: Là danh sách các thuộc tính muốn lấy, nếu là null thì sẽ kết quả trả về tất cả các thuộc tính đang có.

  • onSuccess: Hàm được thực hiện khi server trả kết quả thành công.

  • errorCallBack : Hàm được thực hiện khi có lỗi xảy ra

Code mẫu 1: Lấy theo thuộc tính chỉ định

GSMUser.GetProperties(new PropertyPreset[]
{
    PropertyPreset.name,
    PropertyPreset.data
}, (json) =>
{
    Debug.Log($"User Properties: {json}");
    //Biến đổi từ json sang Dictionary để xử lý
    var dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
    string name = dict["name"].ToString();
    Debug.Log($"name: {name}");
});

Code mẫu 2: Lấy toàn bộ các thuộc tính

GSMUser.GetProperties(null, (json) =>
{
    Debug.Log($"User Properties: {json}");
});

Hoặc

void GetProperties(Action<UserProperties> onSuccess, Action<long, string> errorCallBack = null)

Các tham số

  • onSuccess: Hàm được thực hiện khi server trả kết quả thành công.

  • onFail: Hàm được thực hiện khi có lỗi xảy ra

Code mẫu:

GSMUser.GetProperties(data =>
{
    Debug.Log($"User Name: {data.name}");
    Debug.Log($"User Avatar: {data.avatar}");
    Debug.Log($"iapCount: {data.iapCount}");
    Debug.Log($"iapRevenue: {data.iapRevenue}");
    Debug.Log($"maxIAP: {data.maxIAP}");
    Debug.Log($"avgIAP: {data.avgIAP}");

    if (data.data != null)
    {
        string jsonData = JsonConvert.SerializeObject(data.data);
    }
}, (statusCode, error) =>
{
    Debug.LogError($"GSMUser.GetProperties error: {error}");
});

3. Set Custom Data

  • Mục đích để lưu thêm các thông tin về user, và có thể tùy biến theo từng game

void SetCustomData(Dictionary<string, object> parameters)

Các tham số

  • parameters: Mảng các thuộc key và value

GSMUser.SetCustomData(
    new Dictionary<string, object>() {
        { "level", 1},
        { "userType", "free" }
    }
)

4. Get Custom Data

  • Mục đích lấy các data tùy biến của user đã được set trước đó.

void GetCustomData(List<string> keys, Action<string> onSuccess, Action<long, string> errorCallBack = null)

Các tham số

  • keys: Mảng các thuộc key cần lấy

  • onSuccess: Là action để xử lý kết quả là 1 json.

  • errorCallBack : Action xử lý khi có lỗi xảy ra

GSMUser.GetCustomData(new List<string>() { "level", "userType" }, (result) =>
{
    Debug.Log($"Result: {result}");
});

5. Chức năng Invite

  • Chức năng này dùng khi user A chia sẻ cho user B cài đặt game/app qua link chia sẻ, hoặc có thể nhập mã chia sẻ.

  • Quy trình: (1. User A Lấy mã chia sẻ hoặc link chia sẻ)==> (2. User B cài đặt từ link chia sẻ hoặc nhập mã chia sẻ của user A)

  • Sau khi thực hiện quy trình trên, thì server sẽ ghi nhận user B được chia sẻ từ user A.

3.1 Lấy mã chia sẻ (Dành cho user A)

  • Dùng để lấy ra mã chia sẻ của user, và tạo ra link để user chia sẻ game cho user khác

Code mẫu:

GSMUser.GetInviteCode(inviteCode =>
{
    Debug.Log($"InviteCode: {inviteCode}");
});
  • Đây là link sử dụng link của Adjust, để có thể tạo link thì trên GSM cần phải cấu hình link vào InviteConfig trên GSM

Code mẫu:

GSMUser.GetInviteLink(link =>
{
    //link chia se
});

Last updated