public initialize ( string trackingID, string anonymousClientID, string appName = "", string appVersion = "", bool useHTTPS = false ) : void | ||
trackingID | string | |
anonymousClientID | string | |
appName | string | |
appVersion | string | |
useHTTPS | bool | |
Résultat | 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. // SystemInfo.deviceUniqueIdentifier would be nice for this, but // use of it is abandoned as it can lead to additional required // permissions or submission approval problems on some platforms. // So we only use a combination of timestamp, random value and // some sources of device-specific data to make up an anonymous // id which is also sufficiently unique. int deviceData = SystemInfo.graphicsDeviceName.GetHashCode() ^ SystemInfo.graphicsDeviceVersion.GetHashCode() ^ SystemInfo.operatingSystem.GetHashCode() ^ SystemInfo.processorType.GetHashCode(); clientID = getPOSIXTime().ToString("X8") + Random.Range(0, 0x7fffffff).ToString("x8") + deviceData.ToString("X8"); //Debug.Log("Created client id for analytics: " + clientID); PlayerPrefs.SetString(clientIdPrefKey, clientID); PlayerPrefs.Save(); } string offlineCacheFilePath = ""; // empty string=disable (in GUA class) if (useOfflineCache && offlineCacheFileName != null && offlineCacheFileName.Length > 0) { offlineCacheFilePath = Application.persistentDataPath + '/' + offlineCacheFileName; //Debug.Log("Full path for offline cache: " + offlineCacheFilePath); } //bool useStringEscaping = true; // see the docs about this if (gua == null) { gua = GoogleUniversalAnalytics.Instance; } gua.initialize(this, trackingID, clientID, appName, appVersion, useHTTPS, offlineCacheFilePath); //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.Screenview); gua.addScreenResolution(Screen.currentResolution.width, Screen.currentResolution.height); gua.addViewportSize(Screen.width, Screen.height); gua.addScreenName(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 (sendSystemInfo && (useOfflineCache || gua.internetReachable) && !PlayerPrefs.HasKey(prefKey)) { sendSystemInfoEvent(category, "ScreenResolution", "" + Screen.currentResolution.width + "x" + Screen.currentResolution.height); sendSystemInfoEvent(category, "ViewportSize", "" + Screen.width + "x" + Screen.height); sendSystemInfoEvent(category, "ScreenDPI", ((int)Screen.dpi).ToString(), (int)Screen.dpi); sendSystemInfoEvent(category, "operatingSystem", SystemInfo.operatingSystem); sendSystemInfoEvent(category, "processorType", SystemInfo.processorType); sendSystemInfoEvent(category, "processorCount", SystemInfo.processorCount.ToString(), SystemInfo.processorCount); // round down to 128MB chunks for label sendSystemInfoEvent(category, "systemMemorySize", (128 * (SystemInfo.systemMemorySize / 128)).ToString(), SystemInfo.systemMemorySize); // round down to 16MB chunks for label sendSystemInfoEvent(category, "graphicsMemorySize", (16 * (SystemInfo.graphicsMemorySize / 16)).ToString(), SystemInfo.graphicsMemorySize); sendSystemInfoEvent(category, "graphicsDeviceName", SystemInfo.graphicsDeviceName); sendSystemInfoEvent(category, "graphicsDeviceVendor", SystemInfo.graphicsDeviceVendor); sendSystemInfoEvent(category, "graphicsDeviceID", SystemInfo.graphicsDeviceID.ToString(), SystemInfo.graphicsDeviceID); sendSystemInfoEvent(category, "graphicsDeviceVendorID", SystemInfo.graphicsDeviceVendorID.ToString(), SystemInfo.graphicsDeviceVendorID); sendSystemInfoEvent(category, "graphicsDeviceVersion", SystemInfo.graphicsDeviceVersion); sendSystemInfoEvent(category, "graphicsShaderLevel", SystemInfo.graphicsShaderLevel.ToString(), SystemInfo.graphicsShaderLevel); #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 // (graphicsPixelFillrate is not supported on Unity 5.0+) // 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; } sendSystemInfoEvent(category, "graphicsPixelFillrate", (pixelFillrateChunkSize * (SystemInfo.graphicsPixelFillrate / pixelFillrateChunkSize)).ToString(), SystemInfo.graphicsPixelFillrate); #else // or Unity 5.0+: // New additions in Unity 5.0+: sendSystemInfoEvent(category, "graphicsMultiThreaded", SystemInfo.graphicsMultiThreaded ? "yes" : "no", SystemInfo.graphicsMultiThreaded ? 1 : 0); #endif // Unity 5.0+ sendSystemInfoEvent(category, "deviceType", SystemInfo.deviceType.ToString()); // round down to 512 chunks for label #if !UNITY_3_5 sendSystemInfoEvent(category, "maxTextureSize", (512 * (SystemInfo.maxTextureSize / 512)).ToString(), SystemInfo.maxTextureSize); sendSystemInfoEvent(category, "supports3DTextures", SystemInfo.supports3DTextures ? "yes" : "no", SystemInfo.supports3DTextures ? 1 : 0); sendSystemInfoEvent(category, "supportsComputeShaders", SystemInfo.supportsComputeShaders ? "yes" : "no", SystemInfo.supportsComputeShaders ? 1 : 0); sendSystemInfoEvent(category, "supportsInstancing", SystemInfo.supportsInstancing ? "yes" : "no", SystemInfo.supportsInstancing ? 1 : 0); sendSystemInfoEvent(category, "npotSupport", SystemInfo.npotSupport.ToString()); #endif sendSystemInfoEvent(category, "supportsShadows", SystemInfo.supportsShadows ? "yes" : "no", SystemInfo.supportsShadows ? 1 : 0); sendSystemInfoEvent(category, "supportsRenderTextures", SystemInfo.supportsRenderTextures ? "yes" : "no", SystemInfo.supportsRenderTextures ? 1 : 0); sendSystemInfoEvent(category, "supportedRenderTargetCount", SystemInfo.supportedRenderTargetCount.ToString(), SystemInfo.supportedRenderTargetCount); sendSystemInfoEvent(category, "deviceModel", SystemInfo.deviceModel); sendSystemInfoEvent(category, "supportsAccelerometer", SystemInfo.supportsAccelerometer ? "yes" : "no", SystemInfo.supportsAccelerometer ? 1 : 0); sendSystemInfoEvent(category, "supportsGyroscope", SystemInfo.supportsGyroscope ? "yes" : "no", SystemInfo.supportsGyroscope ? 1 : 0); sendSystemInfoEvent(category, "supportsLocationService", SystemInfo.supportsLocationService ? "yes" : "no", SystemInfo.supportsLocationService ? 1 : 0); sendSystemInfoEvent(category, "supportsVibration", SystemInfo.supportsVibration ? "yes" : "no", SystemInfo.supportsVibration ? 1 : 0); sendSystemInfoEvent(category, "supportsImageEffects", SystemInfo.supportsImageEffects ? "yes" : "no", SystemInfo.supportsImageEffects ? 1 : 0); PlayerPrefs.SetInt(prefKey, getPOSIXTime()); PlayerPrefs.Save(); } // sendSystemInfo } // !gua.analyticsDisabled if (sendExceptions) { Application.RegisterLogCallback(Callback_HandleLog); } } // Awake
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