Skip to main content

Write Log

You can record various information generated from the client.

URL Verification

This API uses the service-api.playnanoo.com domain.

API Information

  • URL: https://service-api.playnanoo.com/gamelog/v20220901/save
  • Method: PUT
  • Authentication Required: Yes
DeviceInfo Inheritance

The Req class of this API inherits from DeviceInfo. All properties of DeviceInfo are automatically included.

Request Parameters

ParameterTypeRequiredDescription
table_codestringRequiredTable code
log_valuestringRequiredLog data (JSON string)
Table Code

You must create a table code in the PlayNANOO admin console before saving game logs.

Response Data

Res Class

FieldTypeDescription
StatusstringProcessing result status

Unity C# Implementation

BaseResponse Class

The base class for all API responses.

public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}

Field descriptions:

  • ErrorCode: Error code
  • Message: Error message
  • WithdrawalKey: Key required for recovery if in withdrawal grace period (provided only for accounts in withdrawal grace period)
  • BlockKey: Key provided for blocked accounts (provided only for blocked accounts)

Game Log Save Class

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class SaveLog
{
static string path = "https://service-api.playnanoo.com/gamelog/v20220901/save";

[Serializable]
public class Req : DeviceInfo
{
// Required
public string table_code;
public string log_value;

public IEnumerator Send(string tableCode, List<LogParamsValueModel> logs, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(tableCode)) this.table_code = tableCode;

if(logs != null && logs.Count > 0)
{
LogParamsModel model = new LogParamsModel { items = logs };
this.log_value = JsonUtility.ToJson(model);
}

yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}

[Serializable]
public class Res : BaseResponse
{
public string Status;
}

[Serializable]
public class LogParamsModel
{
public List<LogParamsValueModel> items;
}

[Serializable]
public class LogParamsValueModel
{
public string key;

public string value;
}

}

Usage Examples

Basic Usage

using PlayNANOO;
using System.Collections.Generic;

public class PlayNANOOExample : MonoBehaviour
{
void SaveGameLog()
{
SaveLog.Req req = new SaveLog.Req();

// Create log data
List<SaveLog.LogParamsValueModel> logs = new List<SaveLog.LogParamsValueModel>
{
new SaveLog.LogParamsValueModel { key = "event_type", value = "level_complete" },
new SaveLog.LogParamsValueModel { key = "level", value = "5" },
new SaveLog.LogParamsValueModel { key = "score", value = "1000" },
new SaveLog.LogParamsValueModel { key = "time_spent", value = "120" }
};

StartCoroutine(req.Send(
tableCode: "your-gamelog-tablecode",
logs: logs,
onSuccess: res =>
{
Debug.Log($"Game log saved successfully: {res.Status}");
},
onError: (error) =>
{
Debug.LogError($"Failed to save game log: [{error.ErrorCode}] [{error.Message}]");
}
));
}
}

Player Action Log Recording

using PlayNANOO;
using System.Collections.Generic;

public class PlayerActionLogger : MonoBehaviour
{
void LogPlayerAction(string actionType, Dictionary<string, string> actionData)
{
SaveLog.Req req = new SaveLog.Req();

// Convert Dictionary to LogParamsValueModel list
List<SaveLog.LogParamsValueModel> logs = new List<SaveLog.LogParamsValueModel>();
logs.Add(new SaveLog.LogParamsValueModel { key = "action_type", value = actionType });

foreach (var kvp in actionData)
{
logs.Add(new SaveLog.LogParamsValueModel { key = kvp.Key, value = kvp.Value });
}

StartCoroutine(req.Send(
tableCode: "player_actions",
logs: logs,
onSuccess: res =>
{
Debug.Log($"Player action log saved successfully");
},
onError: (error) =>
{
Debug.LogError($"Failed to save player action log: [{error.ErrorCode}] [{error.Message}]");
}
));
}

// Usage example
void OnPlayerPurchase()
{
Dictionary<string, string> purchaseData = new Dictionary<string, string>
{
{ "item_id", "sword_001" },
{ "item_name", "Legendary Sword" },
{ "price", "1000" },
{ "currency", "gold" }
};

LogPlayerAction("purchase", purchaseData);
}
}

Game Progress Log

using PlayNANOO;
using System.Collections.Generic;

public class GameProgressLogger : MonoBehaviour
{
void LogStageComplete(int stageNumber, int score, float playTime)
{
SaveLog.Req req = new SaveLog.Req();

List<SaveLog.LogParamsValueModel> logs = new List<SaveLog.LogParamsValueModel>
{
new SaveLog.LogParamsValueModel { key = "event", value = "stage_complete" },
new SaveLog.LogParamsValueModel { key = "stage", value = stageNumber.ToString() },
new SaveLog.LogParamsValueModel { key = "score", value = score.ToString() },
new SaveLog.LogParamsValueModel { key = "play_time", value = playTime.ToString("F2") },
new SaveLog.LogParamsValueModel { key = "timestamp", value = System.DateTime.UtcNow.ToString("o") }
};

StartCoroutine(req.Send(
tableCode: "stage_progress",
logs: logs,
onSuccess: res =>
{
Debug.Log($"Stage completion log saved successfully");
},
onError: (error) =>
{
Debug.LogError($"Failed to save stage completion log: [{error.ErrorCode}] [{error.Message}]");
}
));
}
}
Log Data Format

Log data is passed as a list of LogParamsValueModel, which is internally converted to a JSON string. You can record various data as key-value pairs.

Automatic JSON Conversion

The Send method automatically converts the LogParamsValueModel list to a JSON string and sets it to log_value.

Data Size Limitation

Log data should be kept at an appropriate size. Too large data can affect network performance.