Beispiel #1
0
        /// <summary>
        /// Generates an analytics package and sends it to the Clearcut servers.
        /// </summary>
        /// <param name="analyticsHost">Address of host to send the analytics to.</param>
        /// <param name="logRequest">Data to send to the analytics server.</param>
        public void SendAnalytics(string analyticsHost, LogRequest logRequest)
        {
            // Save the time sending was last attempted.
            _lastUpdateTicks = DateTime.Now.Ticks;

            // Only send if analytics is enabled.
            if (EnableAnalytics == false)
            {
                return;
            }

            // Only allow one instance of the request at a time.
            if (_webRequest != null)
            {
                return;
            }

            // Send the data to the server.
            UnityWebRequest webRequest = new UnityWebRequest(analyticsHost);

            webRequest.method          = UnityWebRequest.kHttpVerbPOST;
            webRequest.uploadHandler   = new UploadHandlerRaw(logRequest.ToByteArray());
            webRequest.downloadHandler = new DownloadHandlerBuffer();
            webRequest.SetRequestHeader("Content-Type", "application/x-protobuf");
            webRequest.SendWebRequest();

            // The editor callback will follow through with this request.
            _webRequest = webRequest;
        }
        /// <summary>
        /// Generates an analytics package and sends it to the Clearcut servers.
        /// </summary>
        /// <param name="analyticsHost">Address of host to send the analytics to.</param>
        /// <param name="logRequest">Data to send to the analytics server.</param>
        /// <param name="verbose">If true, display debug messages in the console.</param>
        public void SendAnalytics(string analyticsHost, LogRequest logRequest, bool verbose)
        {
#if UNITY_2017_1_OR_NEWER
            // Save the time sending was last attempted.
            m_LastUpdateTicks = DateTime.Now.Ticks;

            // Only send if analytics is enabled.
            if (EnableAnalytics == false)
            {
                if (verbose == true)
                {
                    Debug.Log("Google ARCore SDK for Unity analytics is disabled, not sending.");
                }

                return;
            }

            // Only allow one instance of the request at a time.
            if (m_WebRequest != null)
            {
                if (verbose == true)
                {
                    Debug.Log("Google ARCore SDK for Unity analytics is already sending data.");
                }

                return;
            }

            // Send the data to the server.
            UnityWebRequest webRequest = new UnityWebRequest(analyticsHost);
            webRequest.method          = UnityWebRequest.kHttpVerbPOST;
            webRequest.uploadHandler   = new UploadHandlerRaw(logRequest.ToByteArray());
            webRequest.downloadHandler = new DownloadHandlerBuffer();
            webRequest.SetRequestHeader("Content-Type", "application/x-protobuf");
            webRequest.SendWebRequest();

            // Set the verbosity preference for this request.
            m_Verbose = verbose;
            if (verbose == true)
            {
                Debug.Log("Sending Google ARCore SDK for Unity analytics.");
            }

            // The editor callback will follow through with this request.
            m_WebRequest = webRequest;
#endif
        }