/// <summary> /// Initialize AmplitudeSharp /// Takes an API key for the project and, optionally, /// a stream where offline/past events are stored /// </summary> /// <param name="apiKey">api key for the project to stream data to</param> /// <param name="persistenceStream">optinal, stream with saved event data <seealso cref="Uninitialize(Stream)"/></param> /// <param name="logger">Action delegate for logging purposes, if none is specified <see cref="System.Diagnostics.Debug.WriteLine(object)"/> is used</param> /// <returns></returns> public static AmplitudeService Initialize(string apiKey, Action <LogLevel, string> logger = null, Stream persistenceStream = null) { if (apiKey == "<YOUR_API_KEY>") { throw new ArgumentOutOfRangeException(nameof(apiKey), "Please specify Amplitude API key"); } AmplitudeService instance = new AmplitudeService(apiKey); instance.NewSession(); if (Interlocked.CompareExchange(ref s_instance, instance, null) == null) { if (logger == null) { logger = (level, message) => { System.Diagnostics.Debug.WriteLine($"Analytics: [{level}] {message}"); }; } s_logger = logger; instance.StartSendThread(); if (persistenceStream != null) { instance.LoadPastEvents(persistenceStream); } } return(Instance); }