Exemplo n.º 1
0
        /// <summary>
        /// Constructs the consent dialog. Set localize to true to use the
        /// localized content.
        /// </summary>
        /// <returns>The consent dialog.</returns>
        /// <param name="localize">If set to <c>true</c> localize.</param>
        private static ConsentDialog ConstructConsentDialog(bool localize)
        {
            ///
            /// Here we create a consent dialog completely from coding.
            /// The alternative is to use our consent dialog editor in
            /// the Privacy module settings UI to compose the dialog content.
            /// Here we manually pick the correct translation based on the
            /// localization requirement. In a real-world app, you may use
            /// a professional localization tool to do that.
            /// If you're showing the default consent dialog (constructed
            /// with the consent dialog editor), you can insert placeholder
            /// texts into the dialog content and then replace them
            /// with translated texts in script before showing
            /// the dialog for localization purpose.
            ///

            // First check if there's any consent saved previously.
            // If there is, we will set the 'isOn' state of our toggles
            // according to the saved consent to reflect the current consent
            // status on the consent dialog.
            DemoAppConsent consent = DemoAppConsent.LoadDemoAppConsent();

            // First create a new consent dialog.
            ConsentDialog dialog = new ConsentDialog();

            // Title.
            dialog.Title = localize ? FrTitle : EnTitle;

            // Put our disclaimer on top.
            dialog.AppendText(Disclaimer);

            // Add the first paragraph.
            dialog.AppendText(localize ? FrFirstParagraph : EnFirstParagraph);

            // Build and append the Advertising toggle.
            ConsentDialog.Toggle adsToggle = new ConsentDialog.Toggle(AdsToggleId);
            adsToggle.Title                   = localize ? FrAdsToggleTitle : EnAdsToggleTitle;
            adsToggle.OnDescription           = localize ? FrAdsToggleOnDesc : EnAdsToggleOnDesc;
            adsToggle.OffDescription          = localize ? FrAdsToggleOffDesc : EnAdsToggleOffDesc;
            adsToggle.ShouldToggleDescription = true;                                                       // make the description change with the toggle state.
            adsToggle.IsOn = consent != null ? consent.advertisingConsent == ConsentStatus.Granted : false; // reflect previous ads consent if any

            dialog.AppendToggle(adsToggle);

            // Build and append the Notifications toggle.
            ConsentDialog.Toggle notifsToggle = new ConsentDialog.Toggle(NotifsToggleId);
            notifsToggle.Title                   = localize ? FrNotifsToggleTitle : EnNotifsToggleTitle;
            notifsToggle.OnDescription           = localize ? FrNotifsToggleDesc : EnNotifsToggleDesc;
            notifsToggle.ShouldToggleDescription = false;                                                       // use same description for both on & off states.
            notifsToggle.IsOn = consent != null ? consent.notificationConsent == ConsentStatus.Granted : false; // reflect previous notifs consent if any

            dialog.AppendToggle(notifsToggle);

            // Build and append the Unity Analytics toggle.
            // If the opt-out URL for Unity Analytics is available, we'll insert it
            // to the toggle description. Otherwise we'll use the "URL unavailable" description.
            // Note that this toggle is ON by default and is not interactable because we can't opt-out
            // Unity Analytics locally, instead the user must visit the fetched URL to opt-out.
            ConsentDialog.Toggle uaToggle = new ConsentDialog.Toggle(UnityAnalyticsToggleId);
            uaToggle.Title = localize ? FrAnalyticsToggleTitle : EnAnalyticsToggleTitle;
            uaToggle.ShouldToggleDescription = false; // the description won't change when the toggle switches between on & off states.
            uaToggle.IsInteractable          = false; // not interactable
            uaToggle.IsOn = true;                     // consent for UnityAnalytics is ON by default, can opt-out via Unity URL

            if (!string.IsNullOrEmpty(UnityAnalyticsOptOutURL))
            {
                // Unity Analytics opt-out URL is available.
                var description = localize ? FrAnalyticsToogleDesc : EnAnalyticsToogleDesc;
                description            = description.Replace(UnityAnalyticsOptOutURLPlaceholder, UnityAnalyticsOptOutURL); // replace placeholder with actual URL
                uaToggle.OnDescription = description;
            }
            else
            {
                // Unity Analytics opt-out URL is not available.
                uaToggle.OnDescription = localize ? FrAnalyticsToggleUnavailDesc : EnAnalyticsToggleUnavailDesc;
            }

            dialog.AppendToggle(uaToggle);

            // Append the second paragraph.
            dialog.AppendText(localize ? FrSecondParagraph : EnSecondParagraph);

            // Build and append the accept button.
            // A consent dialog should always have at least one button!
            ConsentDialog.Button okButton = new ConsentDialog.Button(AcceptButtonId);
            okButton.Title      = localize ? FrButtonTitle : EnButtonTitle;
            okButton.TitleColor = Color.white;
            okButton.BodyColor  = new Color(66 / 255f, 179 / 255f, 1);

            dialog.AppendButton(okButton);

            return(dialog);
        }
Exemplo n.º 2
0
        void Awake()
        {
            // Checks if we're in EEA region.
            Privacy.IsInEEARegion(result =>
            {
                mIsInEEARegion = result == EEARegionStatus.InEEA;
            });

            // Fetch Unity Analytics URL for use in case the consent dialog
            // is shown from the demo buttons.
            if (string.IsNullOrEmpty(UnityAnalyticsOptOutURL))
            {
                FetchUnityAnalyticsOptOutURL(null, null);
            }

            // If we think consent is not needed for our app (or the current device
            // is not in EEA region), we can just
            // go ahead and initialize EM runtime as normal.
            if (!shouldRequestConsent)
            {
                if (RuntimeManager.IsInitialized())
                {
                    RuntimeManager.Init();
                }

                return;
            }

            // Here's the case where we want to ask for consent before initializing.
            // Before initialization we need to check
            // if we have user's data privacy consent or not.
            DemoAppConsent consent = DemoAppConsent.LoadDemoAppConsent();

            // If there's a stored consent:
            // the implementation of this demo app guarantees
            // that this consent was forwarded to relevant modules before it was stored.
            // These modules would have automatically stored their own consent persistently
            // and use that consent during initialization.
            // In short we'll just go ahead with initializing the EM runtime.
            if (consent != null)
            {
                if (!RuntimeManager.IsInitialized())
                {
                    RuntimeManager.Init();
                }

                return;
            }

            // If there's no consent:
            // We'll show the demo consent dialog and ask the user for data privacy consent
            // before initializing EM runtime. In a real-world app, you would also want
            // to postpone the initialization of any 3rd-party SDK that requires consent until
            // such consent is obtained via the consent dialog.
            // ---
            // First fetch the UnityAds opt-out URL which is needed for the consent dialog.
            // Once it's fetched, we'll show the dialog. Once the dialog completes, we'll
            // initialize EM runtime, see DemoDialog_Completed event handler below.
            FetchUnityAnalyticsOptOutURL(
                (url) =>
            {
                // Success: show the demo consent dialog in English.
                ShowDemoConsentDialog(false);
            },
                (error) =>
            {
                // Failure: also show the demo consent dialog in English.
                // The toogle for Unity Analytics will automatically update
                // its description to reflect that the URL is not available.
                ShowDemoConsentDialog(false);
            });
        }