Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User verification tracking #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Assets/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Assets/Editor/CustomMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
//using CryptoUtils;
using System.Linq;

public class CustomMenu
{
[UnityEditor.MenuItem("Editor/Test Vertification")]
static void TestVertification()
{
Debug.Log("Test Vertification...");
string signature = "3044022061b9961d76ede6f38426220552a003186982ea5e48ebc7fdd0074e432689807e0220616f09f35b7c850e62a3c2de342e535d2d095d2f46bc4c62853dd001fb2bf185";
string message = "7B22757365724944223A223C757569643E222C22726F6E696E41646472657373223A2230782E2E2E222C2265786368616E6765644174223A313639313734303530372C2267616D65536C7567223A2270726F6A6563742D74227D";
UserVertification.Vertification(signature, message);
}
}
11 changes: 11 additions & 0 deletions Assets/Editor/CustomMenu.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Assets/Scripts/Analytic/AnalyticManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine;

Expand Down Expand Up @@ -50,6 +51,46 @@ public static void IdentifyLocalUser()
}
}

public static void IdentifyUserData(JObject userData)
{
if (AnalyticManager.initialized)
{
string userId = PlayerPrefs.GetString("userId");
if (string.IsNullOrEmpty(userId))
{
userId = System.Guid.NewGuid().ToString();
PlayerPrefs.SetString("userId", userId);
}

string roninAddress = "";
try
{
roninAddress = userData["roninAddress"].Value<string>();
}
catch (System.Exception ex) { }

AnalyticManager.userId = userId;
#if UNITY_EDITOR
AnalyticManager.env = "dev";
#else
AnalyticManager.env = "staging";
#endif

var jObject = new JObject();
jObject.Add(new JProperty("ronin_address", roninAddress));
jObject.Add(new JProperty("device_name", SystemInfo.deviceModel));
jObject.Add(new JProperty("device_id", SystemInfo.deviceUniqueIdentifier));
jObject.Add(new JProperty("platform_name", Application.platform.ToString()));
jObject.Add(new JProperty("platform_version", SystemInfo.operatingSystem));

jObject.Add(new JProperty("system_memory_size", SystemInfo.systemMemorySize));
jObject.Add(new JProperty("processor_count", SystemInfo.processorCount));
jObject.Add(new JProperty("graphics_device", SystemInfo.graphicsDeviceName));
jObject.Add(new JProperty("graphics_memory_size", SystemInfo.graphicsMemorySize));
AnalyticManager.AddEvent(EventTypes.Identify, jObject);
}
}

public static void InitManager(string apiKey)
{
AnalyticManager.apiKey = apiKey;
Expand Down
18 changes: 16 additions & 2 deletions Assets/Scripts/Analytic/Demo/DemoScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,24 @@ private IEnumerator Start()
AnalyticManager.InitManager(apiKey);
yield return new WaitForEndOfFrame();

AnalyticManager.IdentifyLocalUser(); //INIT IDENTIFY LOCAL USER
string message = "";
string signature = "";
UserVertification.GetArgVertification(out signature, out message);
var userData = UserVertification.Vertification(signature, message);
if (userData != null)
{
AnalyticManager.IdentifyUserData(userData); //INIT IDENTIFY FROM USER DATA (MavisHub)
}
else
{
AnalyticManager.IdentifyLocalUser(); //INIT IDENTIFY LOCAL USER
}

yield return new WaitForEndOfFrame();

AnalyticManager.AddEvent(EventTypes.Screen, new { @event = "demo_screen" });


AnalyticManager.AddEvent(EventTypes.Screen, new { @event = "demo_screen" });
}


Expand Down
70 changes: 70 additions & 0 deletions Assets/Scripts/Analytic/UserVerification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Security.Cryptography;
using System.Text;
using System;
using System.Diagnostics;
using UnityEngine;
using System.Linq;
using Newtonsoft.Json.Linq;

public class UserVertification
{

public static string GetArg(string name)
{
var args = System.Environment.GetCommandLineArgs();
for (int i = 0; i < args.Length; i++)
{
if (args[i] == name && args.Length > i + 1)
{
return args[i + 1];
}
}
return string.Empty;
}



public static void GetArgVertification(out string signature, out string message)
{
signature = GetArg("-signature");
message = GetArg("-message");
}

private static byte[] StringToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}

public static JObject Vertification(string signature, string message)
{
//Example
//open -a test.app --args -message 7B22757365724944223A223C757569643E222C22726F6E696E41646472657373223A2230782E2E2E222C2265786368616E6765644174223A313639313734303530372C2267616D65536C7567223A2270726F6A6563742D74227D -signature 3044022061b9961d76ede6f38426220552a003186982ea5e48ebc7fdd0074e432689807e0220616f09f35b7c850e62a3c2de342e535d2d095d2f46bc4c62853dd001fb2bf185

var messageData = StringToByteArray(message);
var messageStr = System.Text.Encoding.UTF8.GetString(messageData);
var signatureData = StringToByteArray(signature);
UnityEngine.Debug.Log("Message string: " + messageStr);
try
{
JObject userData = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(messageStr);
if (userData != null)
{
UnityEngine.Debug.Log($"User data: {Newtonsoft.Json.JsonConvert.SerializeObject(userData)}");
return userData;
}
else
{
UnityEngine.Debug.LogError("User data is NULL");
return null;
}
}
catch (System.Exception ex)
{
UnityEngine.Debug.LogError(ex);
return null;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Analytic/UserVerification.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions ProjectSettings/BurstAotSettings_StandaloneOSX.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"MonoBehaviour": {
"Version": 4,
"EnableBurstCompilation": true,
"EnableOptimisations": true,
"EnableSafetyChecks": false,
"EnableDebugInAllBuilds": false,
"UsePlatformSDKLinker": false,
"CpuMinTargetX32": 0,
"CpuMaxTargetX32": 0,
"CpuMinTargetX64": 0,
"CpuMaxTargetX64": 0,
"CpuTargetsX64": 72,
"OptimizeFor": 0
}
}
6 changes: 6 additions & 0 deletions ProjectSettings/CommonBurstAotSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"MonoBehaviour": {
"Version": 4,
"DisabledWarnings": ""
}
}