Skip to content

Commit

Permalink
Merge branch 'release/v3.1.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rYuuk authored Aug 8, 2023
2 parents 08fc31b + 83288db commit f486150
Show file tree
Hide file tree
Showing 54 changed files with 3,966 additions and 427 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @HarrisonHough, @rYuuk and @srcnalt will be requested for
# @HarrisonHough, @rYuuk will be requested for
# review when someone opens a pull request.
* @HarrisonHough @rYuuk @srcnalt
* @HarrisonHough @rYuuk

Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@

namespace ReadyPlayerMe.Core.Analytics
{
public class AnalyticsEventLogger : IAnalyticsEventLogger
public class AmplitudeEditorLogger : IAnalyticsEditorLogger
{
private readonly AmplitudeEventLogger amplitudeEventLogger;
private const string SDK_TARGET = "Unity";

private readonly Dictionary<HelpSubject, string> helpDataMap = new Dictionary<HelpSubject, string>
{
{ HelpSubject.AvatarCaching, "avatar caching" },
{ HelpSubject.Subdomain, "subdomain" },
{ HelpSubject.AvatarConfig, "avatar config" },
{ HelpSubject.GltfDeferAgent, "gltf defer agent" },
{ HelpSubject.LoadingAvatars, "download avatar into scene" }
};

private bool isEnabled;
private readonly AppData appData;

public AnalyticsEventLogger(bool isEnabled)
public AmplitudeEditorLogger(bool isEnabled)
{
amplitudeEventLogger = new AmplitudeEventLogger();
this.isEnabled = isEnabled;
appData = ApplicationData.GetData();
}

public void Enable()
{
isEnabled = true;
if (!amplitudeEventLogger.IsSessionIdSet())
if (!AmplitudeEventLogger.IsSessionIdSet())
{
GenerateSessionId();
}
Expand All @@ -32,24 +42,24 @@ public void Disable()
{
ToggleAnalytics(false);
isEnabled = false;
amplitudeEventLogger.SetSessionId(0);
AmplitudeEventLogger.SetSessionId(0);
}

public void IdentifyUser()
{
if (!isEnabled) return;
if (!amplitudeEventLogger.IsSessionIdSet())
if (!AmplitudeEventLogger.IsSessionIdSet())
{
GenerateSessionId();
}
amplitudeEventLogger.SetUserProperties();
SetUserProperties();
}

public void LogOpenProject()
{
if (!isEnabled) return;
GenerateSessionId();
amplitudeEventLogger.LogEvent(Constants.EventName.OPEN_PROJECT);
AmplitudeEventLogger.LogEvent(Constants.EventName.OPEN_PROJECT);
}

public void LogCloseProject()
Expand Down Expand Up @@ -110,13 +120,7 @@ public void LogOpenDialog(string dialog)
{ Constants.Properties.DIALOG, dialog }
});
}

private void LogEvent(string eventName, Dictionary<string, object> eventProperties = null, Dictionary<string, object> userProperties = null)
{
if (!isEnabled) return;
amplitudeEventLogger.LogEvent(eventName, eventProperties, userProperties);
}


public void LogBuildApplication(string target, string appName, bool productionBuild)
{
LogEvent(Constants.EventName.BUILD_APPLICATION, new Dictionary<string, object>
Expand Down Expand Up @@ -144,30 +148,6 @@ public void LogAvatarLoaded(double duration)
});
}

private void GenerateSessionId()
{
amplitudeEventLogger.SetSessionId(DateTimeOffset.Now.ToUnixTimeMilliseconds());
}

private void ToggleAnalytics(bool allow)
{
AppData appData = ApplicationData.GetData();
LogEvent(Constants.EventName.ALLOW_ANALYTICS, new Dictionary<string, object>
{
{ Constants.Properties.ALLOW, allow }
}, new Dictionary<string, object>
{
{ Constants.Properties.ENGINE_VERSION, appData.UnityVersion },
{ Constants.Properties.RENDER_PIPELINE, appData.RenderPipeline },
{ Constants.Properties.SUBDOMAIN, appData.PartnerName },
{ Constants.Properties.APP_NAME, PlayerSettings.productName },
{ Constants.Properties.SDK_TARGET, "Unity" },
{ Constants.Properties.APP_IDENTIFIER, Application.identifier },
{ Constants.Properties.ALLOW_ANALYTICS, allow }
});
}


public void LogCheckForUpdates()
{
LogEvent(Constants.EventName.CHECK_FOR_UPDATES);
Expand Down Expand Up @@ -208,22 +188,94 @@ public void LogFindOutMore(HelpSubject subject)
{
LogEvent(Constants.EventName.FIND_OUT_MORE, new Dictionary<string, object>
{
{ Constants.Properties.CONTEXT, GetSubjectName(subject) }
{ Constants.Properties.CONTEXT, helpDataMap[subject] }
});
}

public static string GetSubjectName(HelpSubject helpSubject)
public void LogOpenSetupGuide()
{
return HelpDataMap[helpSubject];
LogEvent(Constants.EventName.OPEN_SETUP_GUIDE);
}

private static readonly Dictionary<HelpSubject, string> HelpDataMap = new Dictionary<HelpSubject, string>
public void LogOpenIntegrationGuide()
{
{ HelpSubject.AvatarCaching, "avatar caching" },
{ HelpSubject.Subdomain, "subdomain" },
{ HelpSubject.AvatarConfig, "avatar config" },
{ HelpSubject.GltfDeferAgent, "gltf defer agent" },
{ HelpSubject.LoadingAvatars, "download avatar into scene" }
};
LogEvent(Constants.EventName.OPEN_INTEGRATION_GUIDE);
}

public void LogLoadQuickStartScene()
{
LogEvent(Constants.EventName.LOAD_QUICK_START_SCENE);
}

public void LogOpenAvatarDocumentation()
{
LogEvent(Constants.EventName.OPEN_AVATAR_DOCUMENTATION);
}

public void LogOpenAnimationDocumentation()
{
LogEvent(Constants.EventName.OPEN_ANIMATION_DOCUMENTATION);
}

public void LogOpenAvatarCreatorDocumentation()
{
LogEvent(Constants.EventName.OPEN_AVATAR_CREATOR_DOCUMENTATION);
}

public void LogOpenOptimizationDocumentation()
{
LogEvent(Constants.EventName.OPEN_OPTIMIZATION_DOCUMENTATION);
}

private void SetUserProperties()
{
var userProperties = new Dictionary<string, object>
{
{ Constants.Properties.ENGINE_VERSION, appData.UnityVersion },
{ Constants.Properties.RENDER_PIPELINE, appData.RenderPipeline },
{ Constants.Properties.SUBDOMAIN, appData.PartnerName },
{ Constants.Properties.APP_NAME, PlayerSettings.productName },
{ Constants.Properties.SDK_TARGET, SDK_TARGET },
{ Constants.Properties.APP_IDENTIFIER, Application.identifier },
{ Constants.Properties.ALLOW_ANALYTICS, true }
};

Dictionary<string, string> modules = ModuleList.GetInstalledModuleVersionDictionary();

foreach (KeyValuePair<string, string> module in modules)
{
userProperties.Add(module.Key, module.Value);
}

LogEvent(Constants.EventName.SET_USER_PROPERTIES, null, userProperties);
}

private void GenerateSessionId()
{
AmplitudeEventLogger.SetSessionId(DateTimeOffset.Now.ToUnixTimeMilliseconds());
}

private void ToggleAnalytics(bool allow)
{
LogEvent(Constants.EventName.ALLOW_ANALYTICS, new Dictionary<string, object>
{
{ Constants.Properties.ALLOW, allow }
}, new Dictionary<string, object>
{
{ Constants.Properties.ENGINE_VERSION, appData.UnityVersion },
{ Constants.Properties.RENDER_PIPELINE, appData.RenderPipeline },
{ Constants.Properties.SUBDOMAIN, appData.PartnerName },
{ Constants.Properties.APP_NAME, PlayerSettings.productName },
{ Constants.Properties.SDK_TARGET, "Unity" },
{ Constants.Properties.APP_IDENTIFIER, Application.identifier },
{ Constants.Properties.ALLOW_ANALYTICS, allow }
});
}

private void LogEvent(string eventName, Dictionary<string, object> eventProperties = null, Dictionary<string, object> userProperties = null)
{
if (!isEnabled) return;
AmplitudeEventLogger.LogEvent(eventName, eventProperties, userProperties);
}
}
}
160 changes: 0 additions & 160 deletions Editor/Analytics/AmplitudeEventLogger.cs

This file was deleted.

Loading

0 comments on commit f486150

Please sign in to comment.