public addApplicationVersion ( string text = null ) : void | ||
text | string | |
return | void |
void Awake() { //Debug.Log("AnalyticsTesting Awake()"); // prevent additional Analytics objects being created on level reloads if (instance) { DestroyImmediate(this.gameObject); return; } instance = this; DontDestroyOnLoad(gameObject); string clientID = ""; const string clientIdPrefKey = "GoogleUniversalAnalytics_clientID"; // If you want to force a new client ID for temporary testing, // uncomment following line for a single run: //////// PlayerPrefs.DeleteKey(clientIdPrefKey); // (remember to disable it again) if (PlayerPrefs.HasKey(clientIdPrefKey)) { clientID = PlayerPrefs.GetString(clientIdPrefKey); } if (clientID.Length < 8 || !PlayerPrefs.HasKey(clientIdPrefKey)) { // Need to generate unique & anonymous client ID for analytics. #if UNITY_ANDROID // Don't use SystemInfo.deviceUniqueIdentifier on Android, // as it would add requirement of READ_PHONE_STATE permission. // So we only use self-generated timestamp + random value. //Debug.Log("Creating new Android clientID for analytics..."); clientID = getPOSIXTime().ToString("X8") + Random.Range(0, 0x7fffffff).ToString("x8"); #else // On most platforms we use device unique identifier but // additionally shuffle a random value inside it to make // sure it's anonymous. char[] id = (Random.Range(0, 0x7fffffff).ToString("x8") + SystemInfo.deviceUniqueIdentifier).ToCharArray(); for (int a = 0; a < 8; ++a) { char c = id[a]; int idx = Random.Range(0, id.Length); id[a] = id[idx]; id[idx] = c; } clientID = new string(id); #endif //Debug.Log("Created client id for analytics: " + clientID); PlayerPrefs.SetString(clientIdPrefKey, clientID); PlayerPrefs.Save(); } //bool useStringEscaping = true; // see the docs about this if (gua == null) { gua = GoogleUniversalAnalytics.Instance; } gua.initialize(trackingID, clientID, appName, appVersion, useHTTPS); //gua.setStringEscaping(useStringEscaping); // see the docs about this if (PlayerPrefs.HasKey(disableAnalyticsByUserOptOutPrefKey)) { gua.analyticsDisabled = (PlayerPrefs.GetInt(disableAnalyticsByUserOptOutPrefKey, 0) != 0); } if (!gua.analyticsDisabled) { // Start by sending a hit with some generic info, including an app // screen hit with the first level name, since first scene doesn't get // automatically call to OnLevelWasLoaded. gua.beginHit(GoogleUniversalAnalytics.HitType.Appview); gua.addApplicationVersion(); gua.addScreenResolution(Screen.currentResolution.width, Screen.currentResolution.height); gua.addViewportSize(Screen.width, Screen.height); #if !UNITY_METRO && !UNITY_WEBPLAYER && !UNITY_STANDALONE && !UNITY_3_5 && !UNITY_FLASH gua.addScreenColors(Handheld.use32BitDisplayBuffer ? 32 : 16); #endif // Note: this adds language e.g. as "English", although Google API example has "en-us". gua.addUserLanguage(Application.systemLanguage.ToString()); //gua.addCustomDimension(1, "ScreenDPI"); //gua.addCustomMetric(1, (int)Screen.dpi); gua.addContentDescription(newLevelAnalyticsEventPrefix + Application.loadedLevelName); gua.sendHit(); // Next, client SystemInfo statistics are submitted ONCE on the first // launch when internet is reachable. // If you make a few version upgrades and at some point want to get // fresh statistics of your active users, update the category string // below and after next update users will re-submit SystemInfo once. const string category = "SystemInfo_since_v001"; const string prefKey = "GoogleUniversalAnalytics_" + category; // Existing pref key could be deleted with following command: //// PlayerPrefs.DeleteKey(prefKey); // Warning: Do not enable that code row here (except for single time // testing). Otherwise all following single time statistics // hits would be sent on each launch. if (Application.internetReachability != NetworkReachability.NotReachable && !PlayerPrefs.HasKey(prefKey)) { gua.sendEventHit(category, "ScreenDPI", ((int)Screen.dpi).ToString(), (int)Screen.dpi); gua.sendEventHit(category, "operatingSystem", SystemInfo.operatingSystem); gua.sendEventHit(category, "processorType", SystemInfo.processorType); gua.sendEventHit(category, "processorCount", SystemInfo.processorCount.ToString(), SystemInfo.processorCount); // round down to 128MB chunks for label gua.sendEventHit(category, "systemMemorySize", (128 * (SystemInfo.systemMemorySize / 128)).ToString(), SystemInfo.systemMemorySize); // round down to 16MB chunks for label gua.sendEventHit(category, "graphicsMemorySize", (16 * (SystemInfo.graphicsMemorySize / 16)).ToString(), SystemInfo.graphicsMemorySize); gua.sendEventHit(category, "graphicsDeviceName", SystemInfo.graphicsDeviceName); gua.sendEventHit(category, "graphicsDeviceVendor", SystemInfo.graphicsDeviceVendor); gua.sendEventHit(category, "graphicsDeviceID", SystemInfo.graphicsDeviceID.ToString(), SystemInfo.graphicsDeviceID); gua.sendEventHit(category, "graphicsDeviceVendorID", SystemInfo.graphicsDeviceVendorID.ToString(), SystemInfo.graphicsDeviceVendorID); gua.sendEventHit(category, "graphicsDeviceVersion", SystemInfo.graphicsDeviceVersion); gua.sendEventHit(category, "graphicsShaderLevel", SystemInfo.graphicsShaderLevel.ToString(), SystemInfo.graphicsShaderLevel); // round down to chunks for label (10-5000 MPix depending on value range) int pixelFillrateChunkSize = 5000; if (SystemInfo.graphicsPixelFillrate < 40000) { pixelFillrateChunkSize = 2000; } if (SystemInfo.graphicsPixelFillrate < 10000) { pixelFillrateChunkSize = 1000; } else if (SystemInfo.graphicsPixelFillrate < 4000) { pixelFillrateChunkSize = 500; } else if (SystemInfo.graphicsPixelFillrate < 1300) { pixelFillrateChunkSize = 100; } else if (SystemInfo.graphicsPixelFillrate < 200) { pixelFillrateChunkSize = 20; } else if (SystemInfo.graphicsPixelFillrate < 100) { pixelFillrateChunkSize = 10; } gua.sendEventHit(category, "graphicsPixelFillrate", (pixelFillrateChunkSize * (SystemInfo.graphicsPixelFillrate / pixelFillrateChunkSize)).ToString(), SystemInfo.graphicsPixelFillrate); gua.sendEventHit(category, "deviceType", SystemInfo.deviceType.ToString()); // round down to 512 chunks for label #if !UNITY_3_5 gua.sendEventHit(category, "maxTextureSize", (512 * (SystemInfo.maxTextureSize / 512)).ToString(), SystemInfo.maxTextureSize); gua.sendEventHit(category, "supports3DTextures", SystemInfo.supports3DTextures ? "yes" : "no", SystemInfo.supports3DTextures ? 1 : 0); gua.sendEventHit(category, "supportsComputeShaders", SystemInfo.supportsComputeShaders ? "yes" : "no", SystemInfo.supportsComputeShaders ? 1 : 0); gua.sendEventHit(category, "supportsInstancing", SystemInfo.supportsInstancing ? "yes" : "no", SystemInfo.supportsInstancing ? 1 : 0); gua.sendEventHit(category, "npotSupport", SystemInfo.npotSupport.ToString()); #endif gua.sendEventHit(category, "supportsShadows", SystemInfo.supportsShadows ? "yes" : "no", SystemInfo.supportsShadows ? 1 : 0); gua.sendEventHit(category, "supportsRenderTextures", SystemInfo.supportsRenderTextures ? "yes" : "no", SystemInfo.supportsRenderTextures ? 1 : 0); gua.sendEventHit(category, "supportedRenderTargetCount", SystemInfo.supportedRenderTargetCount.ToString(), SystemInfo.supportedRenderTargetCount); gua.sendEventHit(category, "deviceModel", SystemInfo.deviceModel); gua.sendEventHit(category, "supportsAccelerometer", SystemInfo.supportsAccelerometer ? "yes" : "no", SystemInfo.supportsAccelerometer ? 1 : 0); gua.sendEventHit(category, "supportsGyroscope", SystemInfo.supportsGyroscope ? "yes" : "no", SystemInfo.supportsGyroscope ? 1 : 0); gua.sendEventHit(category, "supportsLocationService", SystemInfo.supportsLocationService ? "yes" : "no", SystemInfo.supportsLocationService ? 1 : 0); gua.sendEventHit(category, "supportsVibration", SystemInfo.supportsVibration ? "yes" : "no", SystemInfo.supportsVibration ? 1 : 0); gua.sendEventHit(category, "supportsImageEffects", SystemInfo.supportsImageEffects ? "yes" : "no", SystemInfo.supportsImageEffects ? 1 : 0); PlayerPrefs.SetInt(prefKey, getPOSIXTime()); PlayerPrefs.Save(); } } // !gua.analyticsDisabled } // Awake