/// <summary> Sets the CooladataTraker to use the specified apiToken when talking to server at endpointUrl. Sets userId to be defualt values in case they are not provided in subsequent trackEvent function calls.</summary> /// <param name="apiToken">API token. Cannot be null.</param> /// <param name="endpointUrl">Endpoint URL. Can be null.</param> /// <param name="userId">User identifier. If null, must send with trackEvent.</param> public void setup(string apiToken, string endpointUrl, string userId) { setupState = SetupState.Called; // inititlaize the queue queue = queue ?? new CoolaDataQueue(long.Parse(defaults["queueMaxSize"]), int.Parse(defaults["maxQueueSizeTriggerPercent"])); //initialize the server communication CoolaDataTracker.endpointUrl = ((!string.IsNullOrEmpty(endpointUrl)) ? endpointUrl : defaults["serviceEndPoint"]); CoolaDataTracker.apiToken = apiToken; // setup batch queue and batch sending batchQueue = batchQueue ?? new CoolaDataBatchQueue(); batchQueue.maxNumberOfBatchs = maxBatchesWaitingForServer; if (isManageSendAttachedToBatchQueue == false) { queue.TriggersBatchSending += ManageBatchSending; isManageSendAttachedToBatchQueue = true; } if (string.IsNullOrEmpty(userId)) { // Try to load the user if from the player prefs string savedUserId = CooladataLocalStorage.LoadUserId(); if (string.IsNullOrEmpty(savedUserId)) { // Generate a random user id System.Guid uid = System.Guid.NewGuid(); instance.userId = uid.ToString(); // Save the user id CooladataLocalStorage.SaveUserId(instance.userId); } else { // We use the saved user id instance.userId = savedUserId; } } else { // We use the user id defined by the user instance.userId = userId; } // Initialize the UTM data coolaDataUTM = new CoolaDataUTM(); setupState = SetupState.Finished; if (isSendEveryIntervalCoroutineRunning == false) { isSendEveryIntervalCoroutineRunning = true; StartCoroutine(TrySendBatchEveryInterval()); } StartCoroutine(GetCalibrationTimeFromServer(apiToken)); }
public void OnUISetup() { Debug.Log("doSetup. serverAddress: " + mServerAddressInputField.text + ", apiKey: " + mAPIKeyInputField.text + ", userId: " + mUserIdInputField.text); mSetupPanel.SetActive(false); mLogPanel.SetActive(true); mEventsPanel.SetActive(true); // Setup cooladata CoolaDataTracker.getInstance().setup(mAPIKeyInputField.text, mServerAddressInputField.text, mUserIdInputField.text); AddToLog("UTM data abailable: " + CoolaDataTracker.coolaDataUTM.DataAvailable); // // Save the local data // CooladataLocalStorage.SaveParam(Constants.SERVER_ADDRESS_LOCAL_STORAGE_STR, mServerAddressInputField.text); CooladataLocalStorage.SaveParam(Constants.API_KEY_LOCAL_STORAGE_STR, mAPIKeyInputField.text); CooladataLocalStorage.SaveParam(Constants.USER_ID_LOCAL_STORAGE_STR, mUserIdInputField.text); }
void Start() { // // Get all the buttons reference // Button[] buttons = GetComponentsInChildren <Button>(); for (int index = 0; index < buttons.Length; index++) { if (buttons[index].name == "SetupButton") { mSetupButton = buttons[index]; } else if (buttons[index].name == "SendEventButton") { mSendEventButton = buttons[index]; } } // // Get all the input fields reference // InputField[] inputFields = GetComponentsInChildren <InputField>(); for (int index = 0; index < inputFields.Length; index++) { if (inputFields[index].name == "ServerAddressInputField") { mServerAddressInputField = inputFields[index]; } else if (inputFields[index].name == "APIKeyInputField") { mAPIKeyInputField = inputFields[index]; } else if (inputFields[index].name == "UserIdInputField") { mUserIdInputField = inputFields[index]; } else if (inputFields[index].name == "EventNameInputField") { mEventNameInputField = inputFields[index]; } else if (inputFields[index].name == "ParamNameInputField") { mParamNameInputField = inputFields[index]; } else if (inputFields[index].name == "ParamValueInputField") { mParamValueInputField = inputFields[index]; } } // // Get all the images reference // Image[] images = GetComponentsInChildren <Image>(); for (int index = 0; index < images.Length; index++) { if (images[index].name == "SetupPanel") { mSetupPanel = images[index].gameObject; } else if (images[index].name == "LogsPanel") { mLogPanel = images[index].gameObject; } else if (images[index].name == "EventsPanel") { mEventsPanel = images[index].gameObject; } } // // Get all the text reference // Text[] texts = GetComponentsInChildren <Text>(); for (int index = 0; index < texts.Length; index++) { if (texts[index].name == "LogsText") { mLogsText = texts[index]; } } // // Get all the text reference // Toggle[] toggles = GetComponentsInChildren <Toggle>(); for (int index = 0; index < toggles.Length; index++) { if (toggles[index].name == "ParamSelectionToggle") { mUseParamsToggle = toggles[index]; } } // Register to the operation complete (for tester logs) CoolaDataTracker.getInstance().operationComplete += operationCompleteCallback; // // Try to load local data // mServerAddressInputField.text = CooladataLocalStorage.LoadParam(Constants.SERVER_ADDRESS_LOCAL_STORAGE_STR); mAPIKeyInputField.text = CooladataLocalStorage.LoadParam(Constants.API_KEY_LOCAL_STORAGE_STR); mUserIdInputField.text = CooladataLocalStorage.LoadParam(Constants.USER_ID_LOCAL_STORAGE_STR); // // put default values if no loaded from local storage // if (string.IsNullOrEmpty(mServerAddressInputField.text)) { mServerAddressInputField.text = "https://api.cooladata.com"; } if (string.IsNullOrEmpty(mUserIdInputField.text)) { mUserIdInputField.text = "Unity user"; } // Set the toggle params OnParamsToggleChange(false); // Show only the setup panel mLogPanel.SetActive(false); mEventsPanel.SetActive(false); // eventNameInputField.text = "Test Unity Event"; CheckSetupButton(); CheckSendEventButton(); }