Skip to content

Commit f162d81

Browse files
committed
Change EditorMeasurement to use non-blocking dialog
The consent dialog now uses non-blocking dialog with additional information about the data collection. Change-Id: I5421e10e7f15764f5d48176eb87d3522a643f262
1 parent 08cbc9b commit f162d81

File tree

6 files changed

+180
-152
lines changed

6 files changed

+180
-152
lines changed

source/AndroidResolver/src/PlayServicesResolver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,8 @@ public class AndroidBuildSystemChangedArgs : EventArgs {
756756
BaseQuery = String.Format("version={0}", AndroidResolverVersionNumber.Value.ToString()),
757757
BaseReportName = "Android Resolver: ",
758758
InstallSourceFilename =
759-
System.Reflection.Assembly.GetAssembly(typeof(PlayServicesResolver)).Location
759+
System.Reflection.Assembly.GetAssembly(typeof(PlayServicesResolver)).Location,
760+
DataUsageUrl = VersionHandlerImpl.DATA_USAGE_URL
760761
};
761762

762763
/// <summary>

source/IOSResolver/src/IOSResolver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,8 @@ private delegate void LogMessageDelegate(string message, bool verbose = false,
997997
BasePath = "/iosresolver/",
998998
BaseQuery = String.Format("version={0}", IOSResolverVersionNumber.Value.ToString()),
999999
BaseReportName = "iOS Resolver: ",
1000-
InstallSourceFilename = Assembly.GetAssembly(typeof(IOSResolver)).Location
1000+
InstallSourceFilename = Assembly.GetAssembly(typeof(IOSResolver)).Location,
1001+
DataUsageUrl = VersionHandlerImpl.DATA_USAGE_URL
10011002
};
10021003

10031004
/// <summary>

source/PackageManagerResolver/src/PackageManagerResolver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ internal static void RestoreDefaultSettings() {
619619
BaseQuery =
620620
String.Format("version={0}", PackageManagerResolverVersionNumber.Value.ToString()),
621621
BaseReportName = "Package Manager Resolver: ",
622-
InstallSourceFilename = Assembly.GetAssembly(typeof(PackageManagerResolver)).Location
622+
InstallSourceFilename = Assembly.GetAssembly(typeof(PackageManagerResolver)).Location,
623+
DataUsageUrl = VersionHandlerImpl.DATA_USAGE_URL
623624
};
624625

625626
/// <summary>

source/VersionHandlerImpl/src/EditorMeasurement.cs

Lines changed: 121 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,18 @@ public void RenderGui() {
106106
internal string DataCollectionDescription { get; private set; }
107107

108108
// Strings for the consent request dialog.
109-
internal static string EnableAnalytics = "Enable Analytics";
110-
internal static string RequestConsent =
111-
"Would you like to report {0} usage to the developers?\n\n" +
112-
"This data can be used to improve this product.\n\n" +
113-
"{1}" +
114-
"For more information, see {2} by clicking show policy";
109+
internal static string EnableAnalytics = "Enable Analytics for {0}";
110+
internal static string RequestConsentMessage =
111+
"Would you like to share usage info about the {0} plugin with Google?";
112+
internal static string RequestConsentDataCollection =
113+
"This data can be used to improve this product.";
114+
internal static string RequestConsentLearnMore =
115+
"To learn more about this product, click the “{0}” button.";
116+
internal static string RequestConsentPrivacyPolicy =
117+
"For more information, see {0} by clicking the “{1}” button.";
115118
internal static string Yes = "Yes";
116119
internal static string No = "No";
120+
internal static string LearnMore = "Learn More";
117121
internal static string PrivacyPolicy = "Privacy Policy";
118122

119123
// Global flag that controls whether this class is enabled and should report
@@ -177,7 +181,7 @@ internal string SystemCookie {
177181
/// Delegate that displays a dialog requesting consent to report analytics.
178182
/// This is only exposed for testing purposes.
179183
/// </summary>
180-
internal Dialog.DisplayDelegate displayDialog = Dialog.Display;
184+
internal DialogWindow.DisplayDelegate displayDialog = DialogWindow.Display;
181185

182186
/// <summary>
183187
/// Delegate that opens a URL in an external application.
@@ -236,6 +240,11 @@ internal string SystemCookie {
236240
/// <note>This path must use the system directory separator.<note>
237241
public string InstallSourceFilename { get; set; }
238242

243+
/// <summary>
244+
/// Url to page about the data usage for this measurement.
245+
/// </summary>
246+
public string DataUsageUrl { get; set; }
247+
239248
/// <summary>
240249
/// Generate common query parameters.
241250
/// </summary>
@@ -342,44 +351,62 @@ private static string GetAndCacheUnityRuntimePlatform() {
342351
/// <summary>
343352
/// Ask user to enable analytics.
344353
/// </summary>
345-
/// <param name="complete">Called when the user has selected an option.</param>
346-
public void PromptToEnable(Action complete = null) {
347-
lock (typeof(EditorMeasurement)) {
348-
if (complete == null) complete = () => {};
349-
if (ConsentRequested) {
350-
complete();
351-
} else {
352-
ConsentRequested = true;
353-
displayDialog(
354-
EnableAnalytics,
355-
String.Format(RequestConsent,
356-
PluginName,
357-
String.IsNullOrEmpty(DataCollectionDescription) ? "" :
358-
String.Format("{0}\n\n", DataCollectionDescription),
359-
privacyPolicy),
360-
Dialog.Option.Selected1, Yes, No, PrivacyPolicy,
361-
(selectedOption) => {
362-
lock (typeof(EditorMeasurement)) {
363-
switch (selectedOption) {
364-
case Dialog.Option.Selected0: // Yes
365-
Enabled = true;
366-
complete();
367-
break;
368-
case Dialog.Option.Selected1: // No
369-
Enabled = false;
370-
complete();
371-
break;
372-
case Dialog.Option.Selected2: // Privacy Policy
373-
openUrl(privacyPolicy);
374-
// Display the dialog again so the user has the option of opting
375-
// in or out.
376-
ConsentRequested = false;
377-
PromptToEnable(complete);
378-
break;
379-
}
354+
public void PromptToEnable(Action complete) {
355+
if (ConsentRequested) {
356+
complete();
357+
} else {
358+
displayDialog(
359+
String.Format(EnableAnalytics, PluginName),
360+
String.Format(RequestConsentMessage, PluginName),
361+
DialogWindow.Option.Selected1, Yes, No, "",
362+
windowWidth: 500.0f,
363+
complete: option => {
364+
switch (option) {
365+
case DialogWindow.Option.Selected0: // Yes
366+
Enabled = true;
367+
break;
368+
case DialogWindow.Option.Selected1: // No
369+
Enabled = false;
370+
break;
371+
}
372+
complete();
373+
}, renderContent: dialog => {
374+
GUILayout.Label(RequestConsentDataCollection,
375+
DialogWindow.DefaultLabelStyle);
376+
EditorGUILayout.Space();
377+
378+
if (!String.IsNullOrEmpty(DataCollectionDescription)) {
379+
GUILayout.Label(DataCollectionDescription,
380+
DialogWindow.DefaultLabelStyle);
381+
EditorGUILayout.Space();
382+
}
383+
384+
if (!String.IsNullOrEmpty(DataUsageUrl)) {
385+
GUILayout.Label(String.Format(RequestConsentLearnMore, LearnMore),
386+
DialogWindow.DefaultLabelStyle);
387+
EditorGUILayout.Space();
388+
EditorGUILayout.BeginHorizontal();
389+
if (GUILayout.Button (LearnMore)) {
390+
OpenUrl(DataUsageUrl);
380391
}
381-
}, null, null);
382-
}
392+
EditorGUILayout.Space();
393+
EditorGUILayout.Space();
394+
EditorGUILayout.Space();
395+
EditorGUILayout.EndHorizontal();
396+
EditorGUILayout.Space();
397+
EditorGUILayout.Space();
398+
}
399+
400+
GUILayout.Label(
401+
String.Format(RequestConsentPrivacyPolicy, privacyPolicy, PrivacyPolicy),
402+
DialogWindow.DefaultLabelStyle);
403+
}, renderButtons: dialog => {
404+
if (GUILayout.Button(PrivacyPolicy)) {
405+
OpenUrl(privacyPolicy);
406+
}
407+
EditorGUILayout.Space();
408+
});
409+
ConsentRequested = true;
383410
}
384411
}
385412

@@ -459,55 +486,56 @@ public void Report(string reportUrl, ICollection<KeyValuePair<string, string>> p
459486
public void Report(string reportUrl, string reportName) {
460487
if (!GloballyEnabled) return;
461488

462-
PromptToEnable(complete: () => {
463-
var uri = new Uri("http://ignore.host/" + reportUrl);
464-
bool reported = false;
465-
var path = String.Join("", uri.Segments);
466-
var queryPrefix =
467-
ConcatenateQueryStrings(
468-
ConcatenateQueryStrings(uri.Query,
469-
ConcatenateQueryStrings(CommonQuery, BaseQuery)), "scope=");
470-
var fragment = uri.Fragment;
471-
if (!String.IsNullOrEmpty(BasePath)) path = BasePath + path;
472-
if (!String.IsNullOrEmpty(BaseReportName)) reportName = BaseReportName + reportName;
473-
// Strip all extraneous path separators.
474-
while (path.Contains("//")) path = path.Replace("//", "/");
475-
foreach (var cookie in
476-
new KeyValuePair<string, string>[] {
477-
new KeyValuePair<string, string>(Cookie, queryPrefix + "project"),
478-
new KeyValuePair<string, string>(SystemCookie, queryPrefix + "system")
479-
}) {
480-
if (String.IsNullOrEmpty(cookie.Key)) continue;
481-
// See https://developers.google.com/analytics/devguides/collection/protocol/v1
482-
var status = PortableWebRequest.DefaultInstance.Post(
483-
"http://www.google-analytics.com/collect", null,
484-
new [] {
485-
// Version
486-
new KeyValuePair<string, string>("v", "1"),
487-
// Tracking ID.
488-
new KeyValuePair<string, string>("tid", trackingId),
489-
// Client ID.
490-
new KeyValuePair<string, string>("cid", cookie.Key),
491-
// Hit type.
492-
new KeyValuePair<string, string>("t", "pageview"),
493-
// "URL" / string to report.
494-
new KeyValuePair<string, string>(
495-
"dl", path + "?" + cookie.Value + fragment),
496-
// Document title.
497-
new KeyValuePair<string, string>("dt", reportName),
498-
// Cache buster
499-
new KeyValuePair<string, string>("z", random.Next().ToString())
500-
});
501-
if (status != null) reported = true;
502-
}
503-
if (reported) {
504-
logger.Log(String.Format("Reporting analytics data: {0}{1}{2} '{3}'", path,
505-
String.IsNullOrEmpty(queryPrefix) ? "" : "?" +
506-
queryPrefix, fragment, reportName),
507-
level: LogLevel.Verbose);
508-
}
509-
});
489+
PromptToEnable(() => {
490+
if (!Enabled) return;
491+
492+
var uri = new Uri("http://ignore.host/" + reportUrl);
493+
bool reported = false;
494+
var path = String.Join("", uri.Segments);
495+
var queryPrefix =
496+
ConcatenateQueryStrings(
497+
ConcatenateQueryStrings(uri.Query,
498+
ConcatenateQueryStrings(CommonQuery, BaseQuery)), "scope=");
499+
var fragment = uri.Fragment;
500+
if (!String.IsNullOrEmpty(BasePath)) path = BasePath + path;
501+
if (!String.IsNullOrEmpty(BaseReportName)) reportName = BaseReportName + reportName;
502+
// Strip all extraneous path separators.
503+
while (path.Contains("//")) path = path.Replace("//", "/");
504+
foreach (var cookie in
505+
new KeyValuePair<string, string>[] {
506+
new KeyValuePair<string, string>(Cookie, queryPrefix + "project"),
507+
new KeyValuePair<string, string>(SystemCookie, queryPrefix + "system")
508+
}) {
509+
if (String.IsNullOrEmpty(cookie.Key)) continue;
510+
// See https://developers.google.com/analytics/devguides/collection/protocol/v1
511+
var status = PortableWebRequest.DefaultInstance.Post(
512+
"http://www.google-analytics.com/collect", null,
513+
new [] {
514+
// Version
515+
new KeyValuePair<string, string>("v", "1"),
516+
// Tracking ID.
517+
new KeyValuePair<string, string>("tid", trackingId),
518+
// Client ID.
519+
new KeyValuePair<string, string>("cid", cookie.Key),
520+
// Hit type.
521+
new KeyValuePair<string, string>("t", "pageview"),
522+
// "URL" / string to report.
523+
new KeyValuePair<string, string>("dl",
524+
path + "?" + cookie.Value + fragment),
525+
// Document title.
526+
new KeyValuePair<string, string>("dt", reportName),
527+
// Cache buster
528+
new KeyValuePair<string, string>("z", random.Next().ToString())
529+
});
530+
if (status != null) reported = true;
531+
}
532+
if (reported) {
533+
logger.Log(String.Format("Reporting analytics data: {0}{1}{2} '{3}'", path,
534+
String.IsNullOrEmpty(queryPrefix) ? "" : "?" + queryPrefix,
535+
fragment, reportName),
536+
level: LogLevel.Verbose);
537+
}
538+
});
510539
}
511540
}
512-
513541
}

source/VersionHandlerImpl/src/VersionHandlerImpl.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,8 @@ public static Logger Logger {
22732273
internal const string PLUGIN_SUITE_NAME = "External Dependency Manager";
22742274
// Privacy policy for analytics data usage.
22752275
internal const string PRIVACY_POLICY = "https://policies.google.com/privacy";
2276+
// Product Url
2277+
internal const string DATA_USAGE_URL = "https://github.com/googlesamples/unity-jar-resolver/";
22762278

22772279
// Analytics reporter.
22782280
internal static EditorMeasurement analytics = new EditorMeasurement(
@@ -2281,7 +2283,8 @@ public static Logger Logger {
22812283
BasePath = "/versionhandler/",
22822284
BaseQuery = String.Format("version={0}", VersionHandlerVersionNumber.Value.ToString()),
22832285
BaseReportName = "Version Handler: ",
2284-
InstallSourceFilename = Assembly.GetAssembly(typeof(VersionHandlerImpl)).Location
2286+
InstallSourceFilename = Assembly.GetAssembly(typeof(VersionHandlerImpl)).Location,
2287+
DataUsageUrl = DATA_USAGE_URL
22852288
};
22862289

22872290
/// <summary>

0 commit comments

Comments
 (0)