first commit

This commit is contained in:
Chris
2025-03-12 14:22:16 -04:00
commit 0ad0c01249
1999 changed files with 189708 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
using System;
using System.Globalization;
using SingularityGroup.HotReload.DTO;
using UnityEditor;
using UnityEditor.VSAttribution.HotReload;
using UnityEngine;
using UnityEngine.Analytics;
namespace SingularityGroup.HotReload.Editor {
internal static class Attribution {
internal const string LastLoginKey = "HotReload.Attribution.LastAttributionEventAt";
//Resend attribution event every 12 hours to be safe
static readonly TimeSpan resendPeriod = TimeSpan.FromHours(12);
//The last time the attribution event was sent.
//Returns unix epoch in case it has never been sent before.
static DateTime LastAttributionEventAt {
get {
if(EditorPrefs.HasKey(LastLoginKey)) {
return DateTime.ParseExact(EditorPrefs.GetString(LastLoginKey), "o", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
}
return DateTimeOffset.FromUnixTimeSeconds(0).UtcDateTime;
}
set {
EditorPrefs.SetString(LastLoginKey, value.ToUniversalTime().ToString("o"));
}
}
const string actionName = "Login";
const string partnerName = "The Naughty Cult Ltd.";
public static void RegisterLogin(LoginStatusResponse response) {
//Licensing might not be initialized yet.
//The hwId should be set eventually.
if(response?.hardwareId == null) {
return;
}
//Only forward attribution if this is an asset store build.
//We will still distribute this package outside of the asset store (i.e via our website).
if (!PackageConst.IsAssetStoreBuild) {
return;
}
var now = DateTime.UtcNow;
//If we sent an attribution event in the last 12 hours we should already be good.
if (now - LastAttributionEventAt < resendPeriod) {
return;
}
var result = VSAttribution.SendAttributionEvent(actionName, partnerName, response.hardwareId);
//Retry on transient errors
if (result == AnalyticsResult.NotInitialized) {
return;
}
LastAttributionEventAt = now;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 67658aafb8404f0eb9496812ba4bb8a4
timeCreated: 1678721795

View File

@@ -0,0 +1,68 @@
using System;
using UnityEngine.Analytics;
namespace UnityEditor.VSAttribution.HotReload
{
internal static class VSAttribution
{
const int k_VersionId = 4;
const int k_MaxEventsPerHour = 10;
const int k_MaxNumberOfElements = 1000;
const string k_VendorKey = "unity.vsp-attribution";
const string k_EventName = "vspAttribution";
static bool RegisterEvent()
{
AnalyticsResult result = EditorAnalytics.RegisterEventWithLimit(k_EventName, k_MaxEventsPerHour,
k_MaxNumberOfElements, k_VendorKey, k_VersionId);
var isResultOk = result == AnalyticsResult.Ok;
return isResultOk;
}
[Serializable]
struct VSAttributionData
{
public string actionName;
public string partnerName;
public string customerUid;
public string extra;
}
/// <summary>
/// Registers and attempts to send a Verified Solutions Attribution event.
/// </summary>
/// <param name="actionName">Name of the action, identifying a place this event was called from.</param>
/// <param name="partnerName">Identifiable Verified Solutions Partner's name.</param>
/// <param name="customerUid">Unique identifier of the customer using Partner's Verified Solution.</param>
public static AnalyticsResult SendAttributionEvent(string actionName, string partnerName, string customerUid)
{
try
{
// Are Editor Analytics enabled ? (Preferences)
if (!EditorAnalytics.enabled)
return AnalyticsResult.AnalyticsDisabled;
if (!RegisterEvent())
return AnalyticsResult.InvalidData;
// Create an expected data object
var eventData = new VSAttributionData
{
actionName = actionName,
partnerName = partnerName,
customerUid = customerUid,
extra = "{}"
};
return EditorAnalytics.SendEventWithLimit(k_EventName, eventData, k_VersionId);
}
catch
{
// Fail silently
return AnalyticsResult.AnalyticsDisabled;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d7493a30e78d4ec783ead20baea2c4d2
timeCreated: 1678721534