@@ -106,14 +106,18 @@ public void RenderGui() {
106
106
internal string DataCollectionDescription { get ; private set ; }
107
107
108
108
// 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." ;
115
118
internal static string Yes = "Yes" ;
116
119
internal static string No = "No" ;
120
+ internal static string LearnMore = "Learn More" ;
117
121
internal static string PrivacyPolicy = "Privacy Policy" ;
118
122
119
123
// Global flag that controls whether this class is enabled and should report
@@ -177,7 +181,7 @@ internal string SystemCookie {
177
181
/// Delegate that displays a dialog requesting consent to report analytics.
178
182
/// This is only exposed for testing purposes.
179
183
/// </summary>
180
- internal Dialog . DisplayDelegate displayDialog = Dialog . Display ;
184
+ internal DialogWindow . DisplayDelegate displayDialog = DialogWindow . Display ;
181
185
182
186
/// <summary>
183
187
/// Delegate that opens a URL in an external application.
@@ -236,6 +240,11 @@ internal string SystemCookie {
236
240
/// <note>This path must use the system directory separator.<note>
237
241
public string InstallSourceFilename { get ; set ; }
238
242
243
+ /// <summary>
244
+ /// Url to page about the data usage for this measurement.
245
+ /// </summary>
246
+ public string DataUsageUrl { get ; set ; }
247
+
239
248
/// <summary>
240
249
/// Generate common query parameters.
241
250
/// </summary>
@@ -342,44 +351,62 @@ private static string GetAndCacheUnityRuntimePlatform() {
342
351
/// <summary>
343
352
/// Ask user to enable analytics.
344
353
/// </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 ) ;
380
391
}
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 ;
383
410
}
384
411
}
385
412
@@ -459,55 +486,56 @@ public void Report(string reportUrl, ICollection<KeyValuePair<string, string>> p
459
486
public void Report ( string reportUrl , string reportName ) {
460
487
if ( ! GloballyEnabled ) return ;
461
488
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
+ } ) ;
510
539
}
511
540
}
512
-
513
541
}
0 commit comments