Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 45 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# Unity-SDK
Your plug & play CMP for Unity.

<mark>**Note**: Sourcepoint's Unity SDK can be used for both Android OS and iOS. Sourcepoint's Unity SDK can be integrated with both Android and iOS. Since it embeds native SDKs, and those only work in their respective platforms, the Unity SDK can't be demoed using Unity's Editor.
Sourcepoint's plug and play Unity SDK can be integrated with both Android and iOS.

<mark>**Note**: Sourcepoint's Unity SDK uses ExternalDependencyManager by Google https://github.com/googlesamples/unity-jar-resolver in order to fetch native SDKs and their dependencies. Make sure you resolve all the dependencies mentioned in `Assets/ExternalDependencyManager/Editor/SourcepointDependencies.xml` before building your application.
> **Note**: The Unity SDK can not be demoed using Unity's Editor since it embeds native SDKs and those only work in their respective platforms.
> <br><br>Additionally, this SDK utilizes [ExternalDependencyManager by Google](https://github.com/googlesamples/unity-jar-resolver) in order to fetch native SDKs and their dependencies. Ensure all the dependencies mentioned in `Assets/ExternalDependencyManager/Editor/SourcepointDependencies.xml` are resolved before building your application.

---

# Instantiate consent UI

To start, include the following library namepsace in your script:

```c#
using ConsentManagementProviderLib;
```

1. Construct `List<SpCampaign>` which contains `SpCampaign` objects. Each `SpCampaign` object should consist of `CAMPAIGN_TYPE` along with `TargetingParams` you need.
Construct `List<SpCampaign>` which contains `SpCampaign` objects. Each `SpCampaign` object should consist of `CAMPAIGN_TYPE` along with the `TargetingParams` you need.

```c#
List<SpCampaign> spCampaigns = new List<SpCampaign>();

Expand All @@ -29,7 +33,8 @@ using ConsentManagementProviderLib;
spCampaigns.Add(ios14);
```

2. In order to instantiate & trigger Consent Message Web View, you must call the `CMP.Initialize` function in `Awake` along with spCampaigns, accountId, propertyName and language.<br/> <br/>Additionally, you can also specify a `messageTimeout` which is set to **3 seconds** by default.
In order to instantiate & trigger `Consent Message Web View`, you must call the `CMP.Initialize` function in `Awake` along with `spCampaigns`, `accountId`, `propertyName` and `language`.<br/> <br/>Additionally, you can also specify a `messageTimeout` which, by default, is set to **30 seconds**.

```c#
CMP.Initialize(spCampaigns: spCampaigns,
accountId: 22,
Expand All @@ -39,16 +44,19 @@ using ConsentManagementProviderLib;
messageTimeoutInSeconds: 3);
```

<mark>**Note**: It may take a frame to initialize the CMP library, so we strongly recommend that you `Initialize` in `Awake` separately from `LoadMessage`. We recommend that you `LoadMessage` in `Start` (see example below).</mark>
> **Note**: It may take a frame to initialize the CMP library, so we strongly recommend that you `Initialize` in `Awake` separately from `LoadMessage`. We recommend that you `LoadMessage` in `Start` (see example below).

When the SDK receives the `LoadMessage` call, it will instantiate a webview if the end-user needs to see a message. <br/><br/> If there is a consent profile associated with `authId`, the SDK will bring the consent data from the server, overwriting whatever was stored in the device.

3. Right after the `LoadMessage` call, the SDK will construct the Web View for the end-user. <br/><br/> If there is a consent profile associated with authId "JohnDoe", the SDK will bring the consent data from the server, overwriting whatever was stored in the device.
```c#
private void Start()
{
CMP.LoadMessage(authId: null); // or pass it a String if you wish to use authenticated consent
}
```
3. In order to free memory, call `Dispose` as illustrated in the following example :

In order to free memory, call `Dispose` as illustrated in the following example :

```c#
private void OnDestroy()
{
Expand All @@ -60,15 +68,16 @@ private void OnDestroy()

Consent callbacks allow you to track progress and receive updates of user interaction. We provide the following interfaces:

| Callback | Description |
|------------------------|-------------------------------------------------------------------------------------------------------------------------|
| `IOnConsentUIReady` | Triggered when web view UI is ready and about to show |
| `IOnConsentAction` | Triggered when user made an action, provides you instance of enum `CONSENT_ACTION_TYPE`. See below for more information.|
| `IOnConsentError` | Triggered when something went wrong, provides you instance of Exception |
| `IOnConsentUIFinished` | Triggered when user interaction with web view UI is done and view is about to disappear |
| `IOnConsentReady` | Triggered when server successfully reacted to user's consent, provides you `SpConsent` object with consent info |
| Callback | Description |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `IOnConsentUIReady` | Triggered when web view UI is ready and about to show |
| `IOnConsentAction` | Triggered when user made an action, provides you instance of enum `CONSENT_ACTION_TYPE`. See below for more information. |
| `IOnConsentError` | Triggered when something went wrong, provides you instance of Exception |
| `IOnConsentUIFinished` | Triggered when user interaction with web view UI is done and view is about to disappear |
| `IOnConsentReady` | Triggered when server successfully reacted to user's consent, provides you `SpConsent` object with consent info |

`CONSENT_ACTION_TYPE` can return the following:

```c#
public enum CONSENT_ACTION_TYPE
{
Expand All @@ -82,9 +91,13 @@ public enum CONSENT_ACTION_TYPE
```

# Workflow to handle callbacks using interfaces
Once you created your own script which derives from `MonoBehaviour` and attached this component to your `GameObject` you should:
1. Inherit your script from any number of interfaces from the `IConsentEventHandler` list you are interested in and implement its method(s).<br/>
For example, suppose you want to handle Exception callback via `IOnConsentErrorEventHandler`, and you already implemented `IOnConsentErrorEventHandler` inheritance and `OnConsentError` method in your script and attached this script to generic `GameObject` in hierarchy. What's next?

After you have created your own script which derives from `MonoBehaviour` and attached this component to your `GameObject` you should perform the following:

Inherit your script from any number of interfaces from the `IConsentEventHandler` list you are interested in and implement its method(s).

> Example<br>Suppose you want to handle exception callback via `IOnConsentErrorEventHandler`, and you already implemented `IOnConsentErrorEventHandler` inheritance and `OnConsentError` method in your script and attached this script to generic `GameObject` in hierarchy. What's next?

```c#
public class ConsentEventHandler : MonoBehaviour, IOnConsentError
{
Expand All @@ -94,24 +107,28 @@ public class ConsentEventHandler : MonoBehaviour, IOnConsentError
}
}
```
2. Register your `gameObject` (which implements any inheritor of `IConsentEventHandler` interface) as an event listener with `ConsentMessenger.AddListener` static method. It can be registered any time before you call the `LoadMessage` method (`Awake`, `Start` is enough, but you can adopt registration to your own logic).

Register your `gameObject` (which implements any inheritor of `IConsentEventHandler` interface) as an event listener with `ConsentMessenger.AddListener` static method. It can be registered any time before you call the `LoadMessage` method (`Awake`, `Start` is enough, but you can adopt the registration to your own logic).

> In the example below, we have added the current `gameObject` as listener for `IOnConsentError` events.<br><br>The event will be executed on all components of the game object that can handle it, regardless of whether they are subscribed or not if at least one have registered the `gameObject` as a listener.

```c#
void Awake()
{
ConsentMessenger.AddListener<IOnConsentError>(this.gameObject);
}
```
⤤ Adds current `gameObject` as listener for `IOnConsentError` events ⤣<br/>
<mark>**Note**: The event will be executed on all components of the game object that can handle it, regardless of whether they are subscribed or not if at least one have registered the `gameObject` as a listener.</mark>

3. You should also unregister your listener when it becomes unnecessary due to garbage collection. `OnDestroy` is enough for our purposes:
You should also unregister your listener when it becomes unnecessary due to garbage collection. `OnDestroy` is enough for our purposes:

```c#
private void OnDestroy()
{
ConsentMessenger.RemoveListener<IOnConsentError>(this.gameObject);
}
```
4. The solution is ready. Configure it and deploy!

The solution is ready. Configure it and deploy!

Both calling & handling workflows are implemented in the `ConsentMessageProvider` and `ConsentEventHandler` scripts of our example app accordingly. Feel free to use these components.

Expand Down Expand Up @@ -171,7 +188,8 @@ public class ConsentEventHandler : MonoBehaviour, IOnConsentUIReady, IOnConsentA

# Resurface Privacy Manager

Once a player has completed the consent flow, you may be interested to resurface your privacy manager so the player can see/manage their consents. To do this we provide the `LoadPrivacyManager` method. The following code snippet will show a GDPR privacy manager with default tab open.
Once a player has completed the consent flow, you might want to provide a way for them to resurface the privacy manager so they can see/manage their consents on an ongoing basis. To do this, we provide the `LoadPrivacyManager` method. The following code snippet will show a GDPR privacy manager with the default tab open.

```c#
public void OnPrivacyManagerButtonClick()
{
Expand All @@ -180,7 +198,9 @@ Once a player has completed the consent flow, you may be interested to resurface
tab: PRIVACY_MANAGER_TAB.DEFAULT);
}
```

Below is a list of available tabs in a GDPR privacy manager:

```c#
public enum PRIVACY_MANAGER_TAB
{
Expand All @@ -193,4 +213,4 @@ Below is a list of available tabs in a GDPR privacy manager:

# Build for iOS

Since Unity Editor exports the pre-built project to Xcode on iOS build, there are several necessary steps to perform so you can compile your solution. They are implemented inside the `CMPPostProcessBuild` [PostProcessBuild] script. Feel free supplement or modify it if needed.
Since Unity Editor exports the pre-built project to Xcode on iOS build, there are several necessary steps to perform so you can compile your solution. They are implemented inside the `CMPPostProcessBuild` [PostProcessBuild] script. Supplement or modify it if it is needed.