private string AddCustomVariables <T>(HitBuilder <T> builder) { if (!trackingCodeSet) { return(""); } String url = ""; foreach (KeyValuePair <int, string> entry in builder.GetCustomDimensions()) { if (entry.Value != null) { url += Fields.CUSTOM_DIMENSION.ToString() + entry.Key + "=" + WWW.EscapeURL(entry.Value.ToString()); } } foreach (KeyValuePair <int, float> entry in builder.GetCustomMetrics()) { if (entry.Value != null) { url += Fields.CUSTOM_METRIC.ToString() + entry.Key + "=" + WWW.EscapeURL(entry.Value.ToString()); } } if (!String.IsNullOrEmpty(url)) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log("Added custom variables to hit."); } } return(url); }
private string AddCampaignParameters <T>(HitBuilder <T> builder) { if (!trackingCodeSet) { return(""); } String url = ""; url += AddOptionalMPParameter(Fields.CAMPAIGN_NAME, builder.GetCampaignName()); url += AddOptionalMPParameter(Fields.CAMPAIGN_SOURCE, builder.GetCampaignSource()); url += AddOptionalMPParameter(Fields.CAMPAIGN_MEDIUM, builder.GetCampaignMedium()); url += AddOptionalMPParameter(Fields.CAMPAIGN_KEYWORD, builder.GetCampaignKeyword()); url += AddOptionalMPParameter(Fields.CAMPAIGN_CONTENT, builder.GetCampaignContent()); url += AddOptionalMPParameter(Fields.CAMPAIGN_ID, builder.GetCampaignID()); url += AddOptionalMPParameter(Fields.GCLID, builder.GetGclid()); url += AddOptionalMPParameter(Fields.DCLID, builder.GetDclid()); if (!String.IsNullOrEmpty(url)) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log("Added campaign parameters to hit. url:" + url); } } return(url); }
/* * Make request using yield and coroutine to prevent lock up waiting on request to return. */ public IEnumerator HandleWWW(WWW request) { while (!request.isDone) { yield return(request); if (request.responseHeaders.ContainsKey("STATUS")) { if (request.responseHeaders["STATUS"].Contains("200 OK")) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.INFO)) { Debug.Log("Successfully sent Google Analytics hit with status: " + request.responseHeaders["STATUS"]); } } else { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.LogWarning("Google Analytics hit request rejected with " + "status code " + request.responseHeaders["STATUS"]); } } } else { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.LogWarning("Google Analytics hit request failed with error " + request.error); } } } }
public void LogScreen(AppViewHitBuilder builder) { if (builder.Validate() == null) { return; } if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log("Logging screen."); } mpTracker.LogScreen(builder); }
public void LogException(ExceptionHitBuilder builder) { if (builder.Validate() == null) { return; } if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log("Logging exception."); } mpTracker.LogException(builder); }
public void InitializeTracker() { if (String.IsNullOrEmpty(trackingCode)) { Debug.Log("No tracking code set for 'Other' platforms - hits will not be set"); trackingCodeSet = false; return; } screenRes = Screen.width + "x" + Screen.height; clientId = SystemInfo.deviceUniqueIdentifier; string language = Application.systemLanguage.ToString(); optOut = false; CultureInfo[] cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures); foreach (CultureInfo info in cultureInfos) { if (info.EnglishName == Application.systemLanguage.ToString()) { language = info.Name; } } try { url = "https://www.google-analytics.com/collect?v=1" + AddRequiredMPParameter(Fields.LANGUAGE, language) + AddRequiredMPParameter(Fields.SCREEN_RESOLUTION, screenRes) + AddRequiredMPParameter(Fields.APP_NAME, appName) + AddRequiredMPParameter(Fields.TRACKING_ID, trackingCode) + AddRequiredMPParameter(Fields.APP_ID, bundleIdentifier) + AddRequiredMPParameter(Fields.CLIENT_ID, clientId) + AddRequiredMPParameter(Fields.APP_VERSION, appVersion); if (anonymizeIP) { url += AddOptionalMPParameter(Fields.ANONYMIZE_IP, 1); } if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log("Base URL for hits: " + url); } } catch (Exception) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.Log("Error building url."); } } }
public void InitializeTracker() { if (String.IsNullOrEmpty(trackingCode)) { Debug.Log("Google Analytics: No tracking code set for 'Other' platforms - hits will not be set"); trackingCodeSet = false; return; } if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.INFO)) { Debug.Log("Google Analytics: Platform is not Android or iOS - " + "hits will be sent using measurement protocol."); } screenRes = Screen.width + "x" + Screen.height; if (string.IsNullOrEmpty(SystemInfo.deviceUniqueIdentifier)) { clientId = PlayerPrefs.GetString(playerPrefKeyUUID, GenerateId()); PlayerPrefs.SetString(playerPrefKeyUUID, clientId); } else { clientId = SystemInfo.deviceUniqueIdentifier; } string language = Application.systemLanguage.ToString(); optOut = false; try { url = baseUrl + AddRequiredMPParameter(Fields.LANGUAGE, language) + AddRequiredMPParameter(Fields.SCREEN_RESOLUTION, screenRes) + AddRequiredMPParameter(Fields.APP_NAME, appName) + AddRequiredMPParameter(Fields.TRACKING_ID, trackingCode) + AddRequiredMPParameter(Fields.APP_ID, bundleIdentifier) + AddRequiredMPParameter(Fields.CLIENT_ID, clientId) + AddRequiredMPParameter(Fields.APP_VERSION, appVersion); if (anonymizeIP) { url += AddOptionalMPParameter(Fields.ANONYMIZE_IP, 1); } if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log("Google Analytics: Base URL for hits: " + url); } } catch (Exception) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.Log("Google Analytics: Error building url."); } } }
private async void SendGaHitWithMeasurementProtocol(string url) { if (String.IsNullOrEmpty(url)) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.Log("No tracking code set for 'Other' platforms - hit will not be sent."); } return; } if (dryRun || optOut) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.Log("Dry run or opt out enabled - hits will not be sent."); } return; } if (startSessionOnNextHit) { url += AddOptionalMPParameter(Fields.SESSION_CONTROL, "start"); startSessionOnNextHit = false; } else if (endSessionOnNextHit) { url += AddOptionalMPParameter(Fields.SESSION_CONTROL, "end"); endSessionOnNextHit = false; } // Add random z to avoid caching string newUrl = url + "&z=" + UnityEngine.Random.Range(0, 500); if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log(newUrl); } if (!Application.isEditor) { var httpClient = new HttpClient(); var response = await httpClient.GetAsync(String.Format(newUrl)); response.EnsureSuccessStatusCode(); } }
public void LogTiming(TimingHitBuilder builder) { InitializeTracker(); if (builder.Validate() == null) { return; } if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log("Logging timing."); } #if UNITY_ANDROID && !UNITY_EDITOR androidTracker.LogTiming(builder); #elif UNITY_IPHONE && !UNITY_EDITOR iosTracker.LogTiming(builder); #else mpTracker.LogTiming(builder); #endif }
private string AddRequiredMPParameter(Field parameter, string value) { if (!trackingCodeSet) { return(""); } else if (value == null) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.LogWarning("Value was null for required parameter " + parameter + ". Hit cannot be sent"); } throw new ArgumentNullException(); } else { return(parameter + "=" + WWW.EscapeURL(value)); } }
private void InitializeTracker() { if (!initialized) { if (string.IsNullOrEmpty(productName)) { productName = Application.productName; } if (string.IsNullOrEmpty(bundleIdentifier)) { bundleIdentifier = Application.identifier; } if (string.IsNullOrEmpty(bundleVersion)) { bundleVersion = Application.version; } mpTracker.SetTrackingCode(trackingCode); mpTracker.SetBundleIdentifier(bundleIdentifier); mpTracker.SetAppName(productName); mpTracker.SetAppVersion(bundleVersion); mpTracker.SetLogLevelValue(logLevel); mpTracker.SetAnonymizeIP(anonymizeIP); mpTracker.SetDryRun(isTesting); mpTracker.InitializeTracker(); //Debug.Log("Initializing Google Analytics 0.2."); if (UncaughtExceptionReporting && GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log("Enabling uncaught exception reporting."); } initialized = true; //SetOnTracker(Fields.DEVELOPER_ID, "GbOCSs"); // ??? What does this string mean? if (UncaughtExceptionReporting) { Application.logMessageReceived += HandleException; } } }
private void SendGaHitWithMeasurementProtocol(string url) { if (String.IsNullOrEmpty(url)) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.Log("No tracking code set for 'Other' platforms - hit will not be sent."); } return; } if (dryRun || optOut) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.Log("Dry run or opt out enabled - hits will not be sent."); } return; } if (startSessionOnNextHit) { url += AddOptionalMPParameter(Fields.SESSION_CONTROL, "start"); startSessionOnNextHit = false; } else if (endSessionOnNextHit) { url += AddOptionalMPParameter(Fields.SESSION_CONTROL, "end"); endSessionOnNextHit = false; } // Add random z to avoid caching string newUrl = url + "&z=" + UnityEngine.Random.Range(0, 500); if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log(newUrl); } GoogleAnalyticsV4.getInstance().StartCoroutine(this.HandleWWW(new WWW(newUrl))); }
void Awake() { InitializeTracker(); if (sendLaunchEvent) { LogEvent("Google Analytics", "Auto Instrumentation", "Game Launch", 0); } if (UncaughtExceptionReporting) { #if UNITY_5 || UNITY_2017 Application.logMessageReceived += HandleException; #else Application.RegisterLogCallback(HandleException); #endif if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log("Enabling uncaught exception reporting."); } } }
/* * Make request using yield and coroutine to prevent lock up waiting on request to return. */ public void HandleWWW(UnityWebRequest request) { var op = request.SendWebRequest(); op.completed += operation => { try { if (request.isNetworkError) { Debug.LogWarning($"Google Analytics: Network error {request.error}"); return; } if (request.error == null) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.INFO)) { Debug.Log($"Successfully sent Google Analytics hit: {request.url}"); } } else { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.LogWarning("Google Analytics hit request failed with error " + request.error); } } } finally { request.Dispose(); } }; }
public void InitializeTracker() { if (String.IsNullOrEmpty(trackingCode)) { Debug.Log("No tracking code set for 'Other' platforms - hits will not be set"); trackingCodeSet = false; return; } if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.INFO)) { Debug.Log("Platform is not Android or iOS - " + "hits will be sent using measurement protocol."); } screenRes = Screen.width + "x" + Screen.height; // clientId = SystemInfo.deviceUniqueIdentifier; #if UNITY_WEBGL clientId = PlayerPrefs.GetString(WebglUidKey, string.Empty); if (clientId == string.Empty) { clientId = Guid.NewGuid().ToString(); PlayerPrefs.SetString(WebglUidKey, clientId); } #else clientId = SystemInfo.deviceUniqueIdentifier; #endif string language = Application.systemLanguage.ToString(); optOut = false; #if !UNITY_WP8 CultureInfo[] cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures); foreach (CultureInfo info in cultureInfos) { if (info.EnglishName == Application.systemLanguage.ToString()) { language = info.Name; } } #endif try { url = "https://www.google-analytics.com/collect?v=1" + AddRequiredMPParameter(Fields.LANGUAGE, language) + AddRequiredMPParameter(Fields.SCREEN_RESOLUTION, screenRes) + AddRequiredMPParameter(Fields.APP_NAME, appName) + AddRequiredMPParameter(Fields.TRACKING_ID, trackingCode) + AddRequiredMPParameter(Fields.APP_ID, bundleIdentifier) + AddRequiredMPParameter(Fields.CLIENT_ID, clientId) + AddRequiredMPParameter(Fields.APP_VERSION, appVersion); if (anonymizeIP) { url += AddOptionalMPParameter(Fields.ANONYMIZE_IP, 1); } if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.VERBOSE)) { Debug.Log("Base URL for hits: " + url); } } catch (Exception) { if (GoogleAnalyticsV4.belowThreshold(logLevel, GoogleAnalyticsV4.DebugMode.WARNING)) { Debug.Log("Error building url."); } } }