로그 작성
클라이언트에서 다양하게 발생되는 정보들을 기록할 수 있습니다.
URL 확인
이 API는 service-api.playnanoo.com 도메인을 사용합니다.
API 정보
- URL:
https://service-api.playnanoo.com/gamelog/v20220901/save - Method:
PUT - 인증 필요: 예
DeviceInfo 상속
이 API의 Req 클래스는 DeviceInfo를 상속받습니다. DeviceInfo의 모든 속성이 자동으로 포함됩니다.
요청 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
| table_code | string | 필수 | 테이블 코드 |
| log_value | string | 필수 | 로그 데이터 (JSON 문자열) |
테이블 코드
게임 로그를 저장하기 전에 PlayNANOO 관리자 콘솔에서 테이블 코드를 생성해야 합니다.
응답 데이터
Res 클래스
| 필드 | 타입 | 설명 |
|---|---|---|
| Status | string | 처리 결과 상태 |
Unity C# 구현
BaseResponse 클래스
모든 API 응답의 기본 클래스입니다.
public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}
필드 설명:
ErrorCode: 에러 코드Message: 에러 메시지WithdrawalKey: 탈퇴 유예 상태인 경우 복구에 필요한 키 (탈퇴 유예 중인 계정만 제공)BlockKey: 차단된 계정인 경우 제공되는 키 (차단된 계정만 제공)
게임 로그 저장 클래스
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
{
//필수
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;
}
}
사용 예제
기본 사용법
using PlayNANOO;
using System.Collections.Generic;
public class PlayNANOOExample : MonoBehaviour
{
void SaveGameLog()
{
SaveLog.Req req = new SaveLog.Req();
// 로그 데이터 생성
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($"게임 로그 저장 성공: {res.Status}");
},
onError: (error) =>
{
Debug.LogError($"게임 로그 저장 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
}
플레이어 행동 로그 기록
using PlayNANOO;
using System.Collections.Generic;
public class PlayerActionLogger : MonoBehaviour
{
void LogPlayerAction(string actionType, Dictionary<string, string> actionData)
{
SaveLog.Req req = new SaveLog.Req();
// Dictionary를 LogParamsValueModel 리스트로 변환
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($"플레이어 행동 로그 저장 성공");
},
onError: (error) =>
{
Debug.LogError($"플레이어 행동 로그 저장 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
// 사용 예시
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);
}
}
게임 진행 상황 로그
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($"스테이지 완료 로그 저장 성공");
},
onError: (error) =>
{
Debug.LogError($"스테이지 완료 로그 저장 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
}
로그 데이터 형식
로그 데이터는 LogParamsValueModel의 리스트로 전달되며, 내부적으로 JSON 문자열로 변환됩니다. key-value 쌍으로 다양한 데이터를 기록할 수 있습니다.
자동 JSON 변환
Send 메서드는 LogParamsValueModel 리스트를 자동으로 JSON 문자열로 변환하여 log_value에 설정합니다.
데이터 크기 제한
로그 데이터는 적절한 크기로 유지해야 합니다. 너무 큰 데이터는 네트워크 성능에 영향을 줄 수 있습니다.