Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Logging
- {
- public class Analytics : SingletonFactory.Singleton
- {
- public static class EventNames
- {
- public const string SECTION_ENTRY = "section_entry";
- public const string SECTION_EXIT = "section_exit";
- public const string SECTION_ACTIVITY = "section_activity";
- public const string HOME_INIT = "oculus_home_init";
- public const string HOME_ERROR = "home_error";
- public const string FRAMETIME = "frametime";
- public const string MEMORY_USAGE = "memory_usage";
- public const string OCULUS_WATERFALL = "oculus_waterfall";
- }
- public static class IAPConstants
- {
- public const string FLOW_NAME = "iap_checkout";
- public const string IAP_START = "iap_checkout_start";
- public const string IAP_CANCELLED = "iap_checkout_cancelled";
- public const string IAP_FINISHED = "iap_checkout_finished";
- public const string PURCHASE_TOTAL = "purchase_total";
- public const string PURCHASE_PIN = "purchase_pin";
- }
- public static class ExtraKeys
- {
- public const string FLOW_NAME = "flow";
- public const string STEP = "step";
- public const string IAP_FBID = "iap_id";
- public const string SECTION_NAME = "section_name";
- public const string SUB_SECTION = "sub_section";
- public const string TIME_SPENT = "active_duration_ms";
- public const string ACTIVITY_TYPE = "activity_type";
- public const string ACTIVITY_EXTRA = "activity_extra";
- public const string SORT_TYPE = "sort_type";
- public const string REFERRER = "referrer";
- public const string INIT_STAGE = "stage";
- public const string INIT_START = "time_start";
- public const string INIT_END = "time_end";
- public const string INIT_DURATION = "duration";
- public const string MIN_FRAME_TIME = "min_frame_time";
- public const string AVG_FRAME_TIME = "avg_frame_time";
- public const string MAX_FRAME_TIME = "max_frame_time";
- public const string ERROR_CODE = "code";
- public const string ERROR_DESCRIPTION = "description";
- public const string ERROR_METHOD = "method";
- public const string MEMORY_USED = "memory_used";
- public const string ORIGIN_APP_NAME = "origin_app_name";
- public const string BUILD_VERSION = "build_version";
- public const string PLUGIN_VERSION = "plugin_version";
- }
- public class SectionKeys
- {
- public const string UM = "um";
- public const string HOME_PRIME = "prime";
- public const string HOME_STORE = "store";
- public const string HOME_LIBRARY = "library";
- public const string PDP = "pdp";
- public const string HSW = "hsw";
- public const string COMMERCE = "commerce";
- }
- public class SubSectionKeys
- {
- public const string PDP_OVERVIEW = "overview";
- public const string PDP_GAMEPLAY = "gameplay";
- public const string PDP_DEVELOPER = "developer";
- public const string PDP_MEDIA = "media";
- public const string COMMERCE_PURCHASETOTAL = "purchaseTotal";
- public const string COMMERCE_PINENTRY = "pinEntry";
- public const string COMMERCE_ADDPAYMENT = "addPaymentMethod";
- public const string UM_ACTIVITY = "activity";
- public const string UM_NOTIFICATIONS = "notification";
- public const string UM_FRIENDS = "friends";
- public const string EMPTY = "";
- }
- public class ActivityTypes
- {
- public const string MAIN_NAVIGATION = "main_navigation";
- }
- public class Event
- {
- public string Name;
- public Dictionary<string, object> Extras;
- private static readonly string[] _KEYS_TO_LOG = new string[]
- {
- "section_name",
- "sub_section",
- "active_duration_ms",
- "stage",
- "sort_type"
- };
- public Event(string name)
- {
- this.Name = name;
- this.Extras = new Dictionary<string, object>();
- }
- public Analytics.Event AddExtra(string key, string value)
- {
- this.Extras.Add(key, value);
- return this;
- }
- public Analytics.Event AddCurrentSection(bool triggerSectionInterceptor = false)
- {
- if (Analytics.Instance.timeTracking.ContainsKey(Analytics.TimeTrackerKey.SECTION))
- {
- Analytics.TimeTrackerItems.Section section = (Analytics.TimeTrackerItems.Section)Analytics.Instance.timeTracking[Analytics.TimeTrackerKey.SECTION].Value;
- this.Extras.Add("section_name", section.Name);
- if (triggerSectionInterceptor && section.Interceptor != null)
- {
- section.Interceptor(this);
- }
- }
- if (Analytics.Instance.timeTracking.ContainsKey(Analytics.TimeTrackerKey.SUB_SECTION))
- {
- Analytics.TimeTrackerItems.SubSection subSection = (Analytics.TimeTrackerItems.SubSection)Analytics.Instance.timeTracking[Analytics.TimeTrackerKey.SUB_SECTION].Value;
- this.Extras.Add("sub_section", subSection.Name);
- this.Extras.Add("sort_type", subSection.Sort);
- }
- return this;
- }
- public Analytics.Event AddTimeSpent(long timeSpent)
- {
- this.Extras.Add("active_duration_ms", timeSpent);
- return this;
- }
- public override string ToString()
- {
- string text = string.Empty;
- int num = 0;
- for (int i = 0; i < Analytics.Event._KEYS_TO_LOG.Length; i++)
- {
- if (this.Extras.ContainsKey(Analytics.Event._KEYS_TO_LOG[i]))
- {
- string text2 = text;
- text = string.Concat(new object[]
- {
- text2,
- (num != 0) ? ", " : string.Empty,
- Analytics.Event._KEYS_TO_LOG[i],
- " = ",
- this.Extras[Analytics.Event._KEYS_TO_LOG[i]]
- });
- num++;
- }
- }
- return string.Concat(new object[]
- {
- "Analytics.Event[",
- this.Name,
- "] => ",
- text,
- " + (",
- this.Extras.Count - num,
- ") extras"
- });
- }
- }
- private enum TimeTrackerKey
- {
- SECTION,
- SUB_SECTION
- }
- private class TimeTrackerItems
- {
- public abstract class TimeTrackerItem
- {
- public Analytics.LogInterceptor Interceptor;
- }
- public class Section : Analytics.TimeTrackerItems.TimeTrackerItem
- {
- public string Name;
- }
- public class SubSection : Analytics.TimeTrackerItems.TimeTrackerItem
- {
- public string Name;
- public string Sort;
- }
- }
- private class TimeTracker
- {
- public readonly object Value;
- private readonly long TimeStart;
- public TimeTracker(object value)
- {
- this.Value = value;
- this.TimeStart = Analytics.TimeTracker.Now();
- }
- public long GetTimeSpent()
- {
- return Analytics.TimeTracker.Now() - this.TimeStart;
- }
- private static long Now()
- {
- return DateTime.Now.Ticks / 10000L;
- }
- }
- public delegate void LogInterceptor(Analytics.Event loggingEvent);
- public const string ORIGIN_APP_NAME = "home";
- private static readonly IDictionary<string, string> REFERRER_MAP = new Dictionary<string, string>
- {
- {
- "prime",
- "prime"
- },
- {
- "store",
- "store"
- },
- {
- "library",
- "library"
- },
- {
- "pdp",
- "pdp"
- },
- {
- "commerce",
- "commerce"
- }
- };
- private string lastIAPRoute;
- private long lastIapRouteElapsedTime;
- private Stopwatch stopWatch;
- private readonly IDictionary<Analytics.TimeTrackerKey, Analytics.TimeTracker> timeTracking = new Dictionary<Analytics.TimeTrackerKey, Analytics.TimeTracker>();
- private Analytics.TimeTrackerItems.Section preFocusLostSection;
- private Analytics.TimeTrackerItems.SubSection preFocusLostSubsection;
- private static readonly DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
- private static readonly DateTime sessionStart = DateTime.UtcNow;
- public static Analytics Instance
- {
- get
- {
- return SingletonFactory.Instance.Get<Analytics>();
- }
- }
- public void LogEvent(Analytics.Event loggingEvent, Analytics.LogInterceptor interceptor)
- {
- this.AddStandardData(loggingEvent);
- if (interceptor != null)
- {
- interceptor(loggingEvent);
- }
- Lumberjack.V("Analytics", loggingEvent, new object[0]);
- Singleton<OafConnector>.Instance.RequestMarauderEvent(loggingEvent.Name, loggingEvent.Extras, null);
- }
- private Analytics.Event AddStandardData(Analytics.Event loggingEvent)
- {
- loggingEvent.AddExtra("origin_app_name", "home");
- loggingEvent.AddExtra("build_version", "197670");
- loggingEvent.AddExtra("plugin_version", "198758");
- return loggingEvent;
- }
- public static string GetUnixTimestamp()
- {
- return (DateTime.UtcNow - Analytics.unixEpoch).TotalMilliseconds.ToString(CultureInfo.InvariantCulture);
- }
- public static string GetUnixTimestamp(DateTime dt)
- {
- return (dt - Analytics.unixEpoch).TotalMilliseconds.ToString(CultureInfo.InvariantCulture);
- }
- public static string GetGlobalSectionReferrer(string route)
- {
- string[] array = SnapPath.Split(route, StringSplitOptions.RemoveEmptyEntries);
- if (array.Length >= 1)
- {
- int num = (!array[0].Equals("global")) ? 0 : 1;
- return (!Analytics.REFERRER_MAP.ContainsKey(array[num])) ? null : array[num];
- }
- return null;
- }
- public void OnSectionEnter(string section, Analytics.LogInterceptor interceptor = null)
- {
- this.timeTracking.Add(Analytics.TimeTrackerKey.SECTION, new Analytics.TimeTracker(new Analytics.TimeTrackerItems.Section
- {
- Name = section,
- Interceptor = interceptor
- }));
- }
- public void OnSectionExit(string section)
- {
- Analytics.TimeTracker timeTracker = this.timeTracking[Analytics.TimeTrackerKey.SECTION];
- Analytics.TimeTrackerItems.Section section2 = (Analytics.TimeTrackerItems.Section)timeTracker.Value;
- this.timeTracking.Remove(Analytics.TimeTrackerKey.SECTION);
- }
- public void OnSubSectionEnter(string subsection, string sort, Analytics.LogInterceptor interceptor = null)
- {
- this.timeTracking.Add(Analytics.TimeTrackerKey.SUB_SECTION, new Analytics.TimeTracker(new Analytics.TimeTrackerItems.SubSection
- {
- Name = subsection,
- Sort = sort,
- Interceptor = interceptor
- }));
- this.LogEvent(new Analytics.Event("section_entry").AddCurrentSection(true), interceptor);
- }
- public void OnFrameRateUpdate(float maxFrameTime, float minFrameTime, float avgFrameTime)
- {
- Lumberjack.F("Perf", string.Concat(new object[]
- {
- "max:",
- maxFrameTime,
- ", min:",
- minFrameTime,
- ", avg:",
- avgFrameTime
- }), new string[0]);
- this.LogEvent(new Analytics.Event("frametime").AddExtra("max_frame_time", maxFrameTime.ToString()).AddExtra("min_frame_time", minFrameTime.ToString()).AddExtra("avg_frame_time", avgFrameTime.ToString()), null);
- }
- public void OnMemoryUsageUpdate(string memoryUsage)
- {
- Lumberjack.F("Perf", "memory:" + memoryUsage, new string[0]);
- this.LogEvent(new Analytics.Event("memory_usage").AddExtra("memory_used", memoryUsage), null);
- }
- public void OnSubSectionExit(string subsection, string sort)
- {
- Analytics.TimeTracker timeTracker = this.timeTracking[Analytics.TimeTrackerKey.SUB_SECTION];
- Analytics.TimeTrackerItems.SubSection subSection = (Analytics.TimeTrackerItems.SubSection)timeTracker.Value;
- this.LogEvent(new Analytics.Event("section_exit").AddCurrentSection(true).AddTimeSpent(timeTracker.GetTimeSpent()), subSection.Interceptor);
- this.timeTracking.Remove(Analytics.TimeTrackerKey.SUB_SECTION);
- }
- public void OnActivity(string type, string extra, Analytics.LogInterceptor interceptor = null)
- {
- this.LogEvent(new Analytics.Event("section_activity").AddExtra("activity_type", type).AddExtra("activity_extra", extra).AddCurrentSection(true), interceptor);
- }
- public void OnNewIAPRootLoaded(string currentLocation, Analytics.LogInterceptor interceptor = null)
- {
- Analytics.Event @event = new Analytics.Event("oculus_waterfall");
- @event.AddExtra("flow", "iap_checkout");
- if (this.lastIAPRoute == null)
- {
- @event.AddExtra("step", "iap_checkout_start");
- @event.AddExtra("active_duration_ms", "0");
- this.stopWatch = Stopwatch.StartNew();
- }
- else
- {
- @event.AddExtra("step", this.lastIAPRoute);
- this.lastIAPRoute = currentLocation;
- long elapsedMilliseconds = this.stopWatch.ElapsedMilliseconds;
- long num = elapsedMilliseconds - this.lastIapRouteElapsedTime;
- this.lastIapRouteElapsedTime = elapsedMilliseconds;
- @event.AddExtra("active_duration_ms", num.ToString());
- }
- this.lastIAPRoute = currentLocation;
- this.LogEvent(@event, interceptor);
- }
- public void OnIAPCommerceCancelled(Analytics.LogInterceptor interceptor = null)
- {
- this.LogEvent(this.OnIAPCommerceCompletedHelper("iap_checkout_cancelled", interceptor), interceptor);
- }
- public void OnIAPCommerceFinished(string iapFbid, Analytics.LogInterceptor interceptor = null)
- {
- Analytics.Event @event = this.OnIAPCommerceCompletedHelper("iap_checkout_finished", interceptor);
- @event.AddExtra("iap_id", iapFbid);
- this.LogEvent(@event, interceptor);
- }
- private Analytics.Event OnIAPCommerceCompletedHelper(string finishStepName, Analytics.LogInterceptor interceptor = null)
- {
- this.OnNewIAPRootLoaded(null, interceptor);
- Analytics.Event @event = new Analytics.Event("oculus_waterfall");
- @event.AddExtra("flow", "iap_checkout");
- @event.AddExtra("step", finishStepName);
- @event.AddExtra("active_duration_ms", this.stopWatch.ElapsedMilliseconds.ToString());
- this.lastIAPRoute = null;
- this.lastIapRouteElapsedTime = 0L;
- this.stopWatch.Stop();
- this.stopWatch = null;
- return @event;
- }
- public void OnVRFocusChanged(bool hasFocus)
- {
- if (!hasFocus)
- {
- if (this.timeTracking.ContainsKey(Analytics.TimeTrackerKey.SUB_SECTION))
- {
- this.preFocusLostSubsection = (Analytics.TimeTrackerItems.SubSection)this.timeTracking[Analytics.TimeTrackerKey.SUB_SECTION].Value;
- this.OnSubSectionExit(this.preFocusLostSubsection.Name, this.preFocusLostSubsection.Sort);
- }
- else
- {
- this.preFocusLostSubsection = null;
- }
- if (this.timeTracking.ContainsKey(Analytics.TimeTrackerKey.SECTION))
- {
- this.preFocusLostSection = (Analytics.TimeTrackerItems.Section)this.timeTracking[Analytics.TimeTrackerKey.SECTION].Value;
- this.OnSectionExit(this.preFocusLostSection.Name);
- }
- else
- {
- this.preFocusLostSection = null;
- }
- }
- else
- {
- if (this.preFocusLostSection != null)
- {
- this.OnSectionEnter(this.preFocusLostSection.Name, null);
- this.preFocusLostSection = null;
- }
- if (this.preFocusLostSubsection != null)
- {
- this.OnSubSectionEnter(this.preFocusLostSubsection.Name, this.preFocusLostSubsection.Sort, null);
- this.preFocusLostSubsection = null;
- }
- }
- }
- public void OnApplicationQuit()
- {
- if (this.timeTracking.ContainsKey(Analytics.TimeTrackerKey.SUB_SECTION))
- {
- Analytics.TimeTrackerItems.SubSection subSection = (Analytics.TimeTrackerItems.SubSection)this.timeTracking[Analytics.TimeTrackerKey.SUB_SECTION].Value;
- this.OnSubSectionExit(subSection.Name, subSection.Sort);
- }
- if (this.timeTracking.ContainsKey(Analytics.TimeTrackerKey.SECTION))
- {
- Analytics.TimeTrackerItems.Section section = (Analytics.TimeTrackerItems.Section)this.timeTracking[Analytics.TimeTrackerKey.SECTION].Value;
- this.OnSectionExit(section.Name);
- }
- }
- public void OnErrorReceived(Error error, string requestMethod, Analytics.LogInterceptor interceptor = null)
- {
- this.LogEvent(new Analytics.Event("home_error").AddExtra("code", error.ErrorCode.ToString()).AddExtra("description", error.Description).AddExtra("method", requestMethod), interceptor);
- }
- public void OnHomeInitStep(InitializationAction.Step step, Analytics.LogInterceptor interceptor = null)
- {
- this.LogEvent(new Analytics.Event("oculus_home_init").AddExtra("stage", step.Name).AddExtra("time_start", step.GetTimeStart().ToString()).AddExtra("time_end", step.GetTimeEnd().ToString()).AddExtra("duration", step.GetDuration().ToString()), interceptor);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement