Easy to use Data Privacy plugin for Unity 3D

Updated:

After a lot of frustration with the available Data Privacy plugins, I decided to create my own and finally decided to share it free of charge under the MIT license.

I am using multiple different ads and analytics plugins and I’m not really satisfied with how the available data privacy plugins work together with them. That is why I decided to create my own. I created this plugin to be as simple as possible to use independently from the used ads and analytics plugins. Finally, I made it available for anyone to use free of charge under an MIT license.

Table of contents

Disclaimer

I’m not a lawyer and I’m not claiming this plugin to be 100% legally sound in every situation and country. I created this plugin to use in my own apps and to suit my own needs.

The responsibility to comply with all laws is Yours! Use at your own risk!

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Motivation

All I want is a simple and very easy-to-use data privacy plugin.

  • Easy to understand data privacy permissions dialog
  • In my game, I want to ask what permissions the user gives
  • When the game starts permissions should already be obtained
    • I don’t want to implement complex logic to check if the user already saw the dialog
    • I don’t want to implement complex logic to wait for loading ads or analytics until the user makes his data privacy choices
  • Easy to change the data privacy permissions
    • Updated data privacy permission choice is available for the next ads or analytics API call

How it works

The plugin is implemented as a separate Unity scene, loaded as the first scene at the start of the game. In this way, no data privacy-relevant events will be used before the user makes his choice.

The plugin checks if the user already gave his consent, so that on the next start the game will be loaded directly without showing the data privacy dialog.

In this way, when the game scene is loaded the data privacy permissions are already granted, so no extra logic is required.

All text resources are externalized in JSON files, so it is very easy to add additional language support.

When adding a new language You don’t need to override all the text resources. The texts that are not available in the new language file will have their default value from the English language file.

Get started

Install the plugin

First, download the plugin (find the link at the bottom of this page).

Import the plugin unitypackage file (double-click on the file or in the Unity Editor choose Assets->Import Package->Custom Package…, select the plugin file and finally click the Import button).

The Data Privacy Plugin uses for all texts TextMesh Pro, so You will be prompted automatically from Unity to add it to the project.

Install Data Privacy Plugin in Unity 3D

There is also an example scene to showcase how the plugin works.

Run the example

Open the example scene (Consent_Example/Scenes/ConsetExampleScene.unity) and press the play button.

  • The data privacy consent dialog will be shown only the first time the game is started.
  • From the three checkboxes, only the age verification checkbox is needed to enable the “Start Playing” button.
  • If the user doesn’t select all three checkboxes an “Are you sure?” dialog will be shown.
  • To change the data privacy settings the consent dialog can be opened at any time with the “Data Privacy” button.

Integrate it into your project

Set the ConsentSettingsScene as the first scene in Build

Add the ConsentSettingsScene (Assets->Consent->Scenes->ConsentSettingsScene) to the build settings as the first scene in the build (File->Build Settings… ->Scenes in Build).

Integrate in your project

Set up the main scene

Open the ConsentSettingsScene in the Editor, select the controller, and put the name of the main project scene in the “Main Scene” field:

Set up the main scene

Set the Data Privacy and the Terms links

Change the “privacy_url” and the “terms_url” texts in the texts_en.json (Consent->Resources->texts_en.json) to point to Your privacy and terms pages.

Adapt the text resources

You have to change at least these two resources:

  • title” -> put here the name of Your game instead of “My Super Game Deluxe
  • age_verification” -> put here the name of Your company instead of “My Great Company

Use it in Your Code

There are three methods to check the consent:

ConsentData.GetConsentData().areAnalyticsEnabled
ConsentData.GetConsentData().areTargetedAdsEnabled
ConsentData.GetConsentData().isAgeVerified

You can use this code to show the consent dialog from your settings:

1
2
3
4
    public void ShowPrivacyPolicy() {
        ConsentData.GetConsentData().SetShowConsentDialog();
        SceneManager.LoadScene("ConsentSettingsScene", LoadSceneMode.Single);
    }

Add support for other languages

Adding support for other languages is pretty straightforward.

Create a new JSON file in the Resources folder (Consent/Resources/) in the following format:

texts_<ALPHA-2 country code in lower case>.json

for example for Germany, it will be “texts_de.json“.

Now open the Texts.cs file (Consent->Scripts->Texts.cs) and put a new case for the new language in the GetLang() method.

I already added support for German and overwritten only the “title” variable to show You how to do it.

Download the plugin

You can download the plugin from here:

Recent Posts


Leave a Reply