public static void InternalInitialize() #endif { // Make sure database is ready if (!GAStore.IsTableReady) { return; } EnsurePersistedStates(); GAStore.SetState(DefaultUserIdKey, Instance.DefaultUserId); Initialized = true; #if WINDOWS_UWP || WINDOWS_WSA await StartNewSession(); #else StartNewSession(); #endif if (IsEnabled()) { GAEvents.EnsureEventQueueIsRunning(); } }
public static void AddErrorEvent(EGAErrorSeverity severity, string message) { GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addErrorEvent", () => { if (!IsSdkReady(true, true, "Could not add error event")) { return; } GAEvents.AddErrorEvent(severity, message); }); }
public static void AddDesignEvent(string eventId, IDictionary <string, object> fields = null) { GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addDesignEvent", () => { if (!IsSdkReady(true, true, "Could not add design event")) { return; } GAEvents.AddDesignEvent(eventId, 0, false, fields); }); }
public static void AddDesignEvent(string eventId, double value) { GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addDesignEvent", () => { if (!IsSdkReady(true, true, "Could not add design event")) { return; } GAEvents.AddDesignEvent(eventId, value, true); }); }
public static void AddResourceEvent(EGAResourceFlowType flowType, string currency, float amount, string itemType, string itemId) { GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addResourceEvent", () => { if (!IsSdkReady(true, true, "Could not add resource event")) { return; } GAEvents.AddResourceEvent(flowType, currency, amount, itemType, itemId); }); }
public static void AddBusinessEvent(string currency, int amount, string itemType, string itemId, string cartType) { GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addBusinessEvent", () => { if (!IsSdkReady(true, true, "Could not add business event")) { return; } // Send to events GAEvents.AddBusinessEvent(currency, amount, itemType, itemId, cartType); }); }
public static void EndSessionAndStopQueue() { GAThreading.IgnoreTimer(Instance.SuspendBlockId); if (Initialized) { GALogger.I("Ending session."); GAEvents.StopEventQueue(); if (IsEnabled() && SessionIsStarted()) { GAEvents.AddSessionEndEvent(); SessionStart = 0; } GAThreading.StopThread(); } }
public static void AddProgressionEvent(EGAProgressionStatus progressionStatus, string progression01, string progression02, string progression03, double score) { GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addProgressionEvent", () => { if (!IsSdkReady(true, true, "Could not add progression event")) { return; } // Send to events // TODO(nikolaj): check if this cast from int to double is OK GAEvents.AddProgressionEvent(progressionStatus, progression01, progression02, progression03, score, true); }); }
public static void EndSessionAndStopQueue(bool endThread) { if (Initialized) { if (IsEnabled() && SessionIsStarted()) { GALogger.I("Ending session."); GAEvents.StopEventQueue(); GAEvents.AddSessionEndEvent(); SessionStart = 0; } } if (endThread) { GAThreading.StopThread(); } }
public static void AddErrorEvent(EGAErrorSeverity severity, string message /*, IDictionary<string, object> fields = null*/) { if (_endThread) { return; } GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addErrorEvent", () => { if (!IsSdkReady(true, true, "Could not add error event")) { return; } GAEvents.AddErrorEvent(severity, message, null); }); }
public static void AddDesignEvent(string eventId, double value, IDictionary <string, object> customFields = null, bool mergeFields = false) { if (_endThread) { return; } GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addDesignEvent", () => { if (!IsSdkReady(true, true, "Could not add design event")) { return; } GAEvents.AddDesignEvent(eventId, value, true, customFields, mergeFields); }); }
public static void AddResourceEvent(EGAResourceFlowType flowType, string currency, float amount, string itemType, string itemId, IDictionary <string, object> customFields = null, bool mergeFields = false) { if (_endThread) { return; } GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addResourceEvent", () => { if (!IsSdkReady(true, true, "Could not add resource event")) { return; } GAEvents.AddResourceEvent(flowType, currency, amount, itemType, itemId, customFields, mergeFields); }); }
public static void AddBusinessEvent(string currency, int amount, string itemType, string itemId, string cartType, IDictionary <string, object> customFields = null, bool mergeFields = false) { if (_endThread) { return; } GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addBusinessEvent", () => { if (!IsSdkReady(true, true, "Could not add business event")) { return; } // Send to events GAEvents.AddBusinessEvent(currency, amount, itemType, itemId, cartType, customFields, mergeFields); }); }
public static void AddProgressionEvent(EGAProgressionStatus progressionStatus, string progression01, string progression02, string progression03 /*, IDictionary<string, object> fields = null*/) { if (_endThread) { return; } GADevice.UpdateConnectionType(); GAThreading.PerformTaskOnGAThread("addProgressionEvent", () => { if (!IsSdkReady(true, true, "Could not add progression event")) { return; } // Send to events // TODO(nikolaj): check if this cast from int to double is OK GAEvents.AddProgressionEvent(progressionStatus, progression01, progression02, progression03, 0, false, null); }); }
public static void StartNewSession(EGAHTTPApiResponse initResponse, JSONObject initResponseDict) { // init is ok if (initResponse == EGAHTTPApiResponse.Ok && initResponseDict != null) { // set the time offset - how many seconds the local time is different from servertime long timeOffsetSeconds = 0; if (initResponseDict["server_ts"] != null) { long serverTs = initResponseDict["server_ts"].AsLong; timeOffsetSeconds = CalculateServerTimeOffset(serverTs); } initResponseDict.Add("time_offset", new JSONNumber(timeOffsetSeconds)); // insert new config in sql lite cross session storage GAStore.SetState(SdkConfigCachedKey, initResponseDict.SaveToBinaryBase64()); // set new config and cache in memory Instance.sdkConfigCached = initResponseDict; Instance.sdkConfig = initResponseDict; Instance.InitAuthorized = true; } else if (initResponse == EGAHTTPApiResponse.Unauthorized) { GALogger.W("Initialize SDK failed - Unauthorized"); Instance.InitAuthorized = false; } else { // log the status if no connection if (initResponse == EGAHTTPApiResponse.NoResponse || initResponse == EGAHTTPApiResponse.RequestTimeout) { GALogger.I("Init call (session start) failed - no response. Could be offline or timeout."); } else if (initResponse == EGAHTTPApiResponse.BadResponse || initResponse == EGAHTTPApiResponse.JsonEncodeFailed || initResponse == EGAHTTPApiResponse.JsonDecodeFailed) { GALogger.I("Init call (session start) failed - bad response. Could be bad response from proxy or GA servers."); } else if (initResponse == EGAHTTPApiResponse.BadRequest || initResponse == EGAHTTPApiResponse.UnknownResponseCode) { GALogger.I("Init call (session start) failed - bad request or unknown response."); } // init call failed (perhaps offline) if (Instance.sdkConfig == null) { if (Instance.sdkConfigCached != null) { GALogger.I("Init call (session start) failed - using cached init values."); // set last cross session stored config init values Instance.sdkConfig = Instance.sdkConfigCached; } else { GALogger.I("Init call (session start) failed - using default init values."); // set default init values Instance.sdkConfig = Instance.sdkConfigDefault; } } else { GALogger.I("Init call (session start) failed - using cached init values."); } Instance.InitAuthorized = true; } { JSONNode currentSdkConfig = SdkConfig; if (currentSdkConfig["enabled"].IsBoolean && !currentSdkConfig["enabled"].AsBool) { Instance.Enabled = false; } else if (!Instance.InitAuthorized) { Instance.Enabled = false; } else { Instance.Enabled = true; } } // set offset in state (memory) from current config (config could be from cache etc.) Instance.ClientServerTimeOffset = SdkConfig["time_offset"] != null ? SdkConfig["time_offset"].AsLong : 0; // populate configurations PopulateConfigurations(SdkConfig); // if SDK is disabled in config if (!IsEnabled()) { GALogger.W("Could not start session: SDK is disabled."); // stop event queue // + make sure it's able to restart if another session detects it's enabled again GAEvents.StopEventQueue(); return; } else { GAEvents.EnsureEventQueueIsRunning(); } // generate the new session string newSessionId = Guid.NewGuid().ToString(); string newSessionIdLowercase = newSessionId.ToLowerInvariant(); // Set session id SessionId = newSessionIdLowercase; // Set session start SessionStart = GetClientTsAdjusted(); // Add session start event GAEvents.AddSessionStartEvent(); }