Skip to content

Commit

Permalink
Syncing changes from private repository
Browse files Browse the repository at this point in the history
  • Loading branch information
helium-service committed Aug 1, 2024
1 parent 9e37b01 commit d19177f
Show file tree
Hide file tree
Showing 32 changed files with 537 additions and 161 deletions.
24 changes: 0 additions & 24 deletions .github/pull_request_template.md

This file was deleted.

18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
## Changelog
All notable changes to this project will be documented in this file using the standards as defined at [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0).

Note the first digit of every adapter version corresponds to the major version of the Chartboost Core SDK compatible with that adapter.
Adapters are compatible with any Chartboost Core SDK version within that major version.

### Version 1.0.0 *(2024-08-01)*
This version of the Usercentrics Adapter supports the following native SDK dependencies:
* Android: `com.chartboost:chartboost-core-consent-adapter-usercentrics:1.2.14.+`
* iOS: `ChartboostCoreConsentAdapterUsercentrics ~> 1.2.8.0`

Added:
- Distribution through `https://www.nuget.org`.

Removed:
- `dspName` as a constructor parameter for `UsercentricsParameter`.
- `templateIdToPartnerId` as a needed parameter for `UsercentricsParameter`.

Improvements:
- `templateIdToPartnerId` as an optional parameter for `UsercentricsParameter`.
- Default `Dictionary<string, string>` for `templateIdToPartnerId`, any additional template ids to partner id will be added to this default map.
- Improved wrapping coverage for `UsercentricsOptions`.

### Version 0.2.8-4 *(2023-12-07)*
- This version of the adapter is compatible with Chartboost Core 0.4.0
- Added the ability to set a Template ID to Mediation Partner ID dictionary to facilitate per-partner consent.
Expand Down
22 changes: 22 additions & 0 deletions Chartboost.CSharp.Core.Unity.Consent.Usercentrics.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>Chartboost.CSharp.Core.Unity.Consent.Usercentrics</id>
<version>1.0.0</version>
<title>Chartboost Core Consent Usercentrics</title>
<description>Usercentrics CMP adapter for mediating through Chartboost Core.</description>
<authors>Chartboost</authors>
<owners>Chartboost</owners>
<license type="file">LICENSE.md</license>
<readme>README.md</readme>
<projectUrl>https://www.chartboost.com</projectUrl>
<copyright>Copyright 2024</copyright>
<tags>Chartboost, Consent, Usercentrics, Core, Unity, cs</tags>
<repository type="git" url="https://github.com/ChartBoost/chartboost-core-unity-consent-adapter-usercentrics"/>
<dependencies>
<dependency id="Chartboost.CSharp.Core.Unity" version="1.0.0" />
<dependency id="Chartboost.CSharp.Utilities.Unity" version="1.0.1" />
<dependency id="Chartboost.CSharp.Logging.Unity" version="1.0.0" />
</dependencies>
</metadata>
</package>
7 changes: 7 additions & 0 deletions Chartboost.CSharp.Core.Unity.Consent.Usercentrics.nuspec.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Editor/ChartboostCoreConsentUsercentricDependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
<dependencies>
<androidPackages>
<!-- Usercentrics Dependency -->
<androidPackage spec="com.chartboost:chartboost-core-consent-adapter-usercentrics:0.2.8.1.5@aar"/>
<androidPackage spec="com.usercentrics.sdk:usercentrics-ui:2.8.1"/>
<androidPackage spec="com.chartboost:chartboost-core-consent-adapter-usercentrics:1.2.14.+"/>
</androidPackages>
<iosPods>
<!-- Usercentrics Podspec -->
<iosPod name="ChartboostCoreConsentAdapterUsercentrics" version="0.2.8.0.2" addToAllTargets="true"/>
<iosPod name="ChartboostCoreConsentAdapterUsercentrics" version="~> 1.2.8.0" addToAllTargets="true"/>
</iosPods>
</dependencies>
5 changes: 0 additions & 5 deletions Editor/link.xml

This file was deleted.

3 changes: 0 additions & 3 deletions Editor/link.xml.meta

This file was deleted.

53 changes: 46 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
# Chartboost Core Usercentrics Adapter
# Chartboost Core - Usercentrics Adapter

The Chartboost Core Usercentrics adapter mediates Usercentrics via the Chartboost Core SDK.
The Chartboost Core - Usercentrics Adapter mediates Usercentrics via the Chartboost Core SDK.

## Minimum Requirements

| Plugin | Version |
| ------ | ------ |
| Chartboost Core SDK | 0.0.0+ |
| Cocoapods | 1.11.3+ |
| iOS | 11.0+ |
| Xcode | 14.1+ |
| Android API | 21+ |
| Unity | 2020.3.37f+ |
| Unity | 2022.3.+ |

## Integration

Chartboost Core Usercentrics Adapter is distributed using the public [npm registry](https://www.npmjs.com/search?q=com.chartboost.core.consent.usercentrics) as such it is compatible with the Unity Package Manager (UPM). In order to add the Chartboost Core Usercentrics Adapter to your project, just add the following to your Unity Project's ***manifest.json*** file. The scoped registry section is required in order to fetch packages from the NpmJS registry.

```json
"dependencies": {
"com.chartboost.core.consent.usercentrics": "0.2.8-0",
"com.chartboost.core.consent.usercentrics": "1.0.0",
...
},
"scopedRegistries": [
Expand All @@ -33,12 +32,52 @@ Chartboost Core Usercentrics Adapter is distributed using the public [npm regist
]
```

## Contributions
## Using the public [NuGet package](https://www.nuget.org/packages/Chartboost.CSharp.Core.Unity.Consent.Usercentrics)

To add the Chartboost Core Unity SDK to your project using the NuGet package, you will first need to add the [NugetForUnity](https://github.com/GlitchEnzo/NuGetForUnity) package into your Unity Project.

This can be done by adding the following to your Unity Project's ***manifest.json***

```json
"dependencies": {
"com.github-glitchenzo.nugetforunity": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity",
...
},
```

Once <code>NugetForUnity</code> is installed, search for `Chartboost.CSharp.Core.Unity.Consent.Usercentrics` in the search bar of Nuget Explorer window(Nuget -> Manage Nuget Packages).
You should be able to see the `Chartboost.CSharp.Core.Unity.Consent.Usercentrics` package. Choose the appropriate version and install.

# Usage

## Client Module
In order to use the `UsercentricsAdapter`, a client instance can be passed along with the `ChartboostCore.Initialize` call as seen in the example below:

```csharp
string chartboostApplicationIdentifier = "CHARTBOOST_APPLICATION_IDENTIFIER";

List<Module> modulesToInitialize = new List<Module>();

// create usercentrics options configuration object
UsercentricsOptions usercentricsOptions = new UsercentricsOptions("USERCENTICS_SETTINGS_ID");

// template to partner id can be passed as an optional paramter, but a default set is provided.
UsercentricsAdapter usercentricsAdapter = new UsercentricsAdapter(usercentricsOptions);

modulesToInitialize.Add(usercentricsAdapter);

SDKConfiguration sdkConfig = new SDKConfiguration(chartboostApplicationIdentifier, modulesToInitialize);

// Initialize Chartboost Core and Usercentrics.
ChartboostCore.Initialize(sdkConfig);
```

# Contributions

We are committed to a fully transparent development process and highly appreciate any contributions. Our team regularly monitors and investigates all submissions for the inclusion in our official adapter releases.

Refer to our [CONTRIBUTING](CONTRIBUTING.md) file for more information on how to contribute.

## License
# License

Refer to our [LICENSE](LICENSE.md) file for more information.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "com.chartboost.consent.usercentrics.android",
"name": "Chartboost.Core.Consent.Usercentrics.Android",
"rootNamespace": "Chartboost.Core.Usercentrics.Android",
"references": [
"com.chartboost.consent.usercentrics",
"com.chartboost.core.android",
"com.chartboost.core"
"Chartboost.Core.Consent.Usercentrics",
"Chartboost.Core.Android",
"Chartboost.Core",
"Chartboost.Utilities.Android",
"Chartboost.Logging"
],
"includePlatforms": [
"Android",
Expand Down
122 changes: 103 additions & 19 deletions Runtime/Android/UsercentricsAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,124 @@
using System.Collections.Generic;
using Chartboost.Core.Android.Modules;
using Chartboost.Core.Android.Utilities;
using Chartboost.Logging;
using UnityEngine;
using UnityEngine.Scripting;

namespace Chartboost.Core.Usercentrics.Android
{
internal class UsercentricsAdapter : NativeModule
internal sealed class UsercentricsAdapter : NativeModule
{
private const string Tag = nameof(UsercentricsAdapter);
private const string UsercentricsNamespace = "com.usercentrics.sdk";
// ReSharper disable InconsistentNaming
private const string ClassUsercentricsAdapter = "com.chartboost.core.consent.usercentrics.UsercentricsAdapter";
private const string ClassUsercentricsOptions = "com.usercentrics.sdk.UsercentricsOptions";

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static readonly string ClassUsercentricsOptions = $"{UsercentricsNamespace}.UsercentricsOptions";

private const string FunctionSetRulesetId = "setRuleSetId";
private const string FunctionSetSettingsId = "setSettingsId";
private const string FunctionSetDefaultLanguage = "setDefaultLanguage";
private const string FunctionSetVersion = "setVersion";
private const string FunctionSetTimeoutMillis = "setTimeoutMillis";
private const string FunctionSetConsentMediation = "setConsentMediation";

private const string CommonNamespace = "models.common";
private static readonly string EnumUsercentricsLoggerLevel = $"{UsercentricsNamespace}.{CommonNamespace}.UsercentricsLoggerLevel";
private const string UsercentricsLoggerLevelNone = "NONE";
private const string UsercentricsLoggerLevelError = "ERROR";
private const string UsercentricsLoggerLevelWarning = "WARNING";
private const string UsercentricsLoggerLevelDebug = "DEBUG";
private const string FunctionSetLoggerLevel = "setLoggerLevel";

private static readonly string EnumUsercentricsNetworkMode = $"{UsercentricsNamespace}.{CommonNamespace}.NetworkMode";
private const string UsercentricsNetworkModeWorld = "WORLD";
private const string UsercentricsNetworkModeEU = "EU";
private const string FunctionSetNetworkMode = "setNetworkMode";
// ReSharper restore InconsistentNaming


[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void SetInstance()
{
if (Application.isEditor)
return;

Usercentrics.UsercentricsAdapter.InstanceType = typeof(UsercentricsAdapter);
}

[Preserve]
public UsercentricsAdapter(UsercentricsOptions options, IDictionary<string, string> templateIdToPartnerId) : base(CreateInstance(options, templateIdToPartnerId)) { }


[Preserve]
public UsercentricsAdapter(string dpsName, UsercentricsOptions options, IDictionary<string, string> templateIdToPartnerId) : base(CreateInstance(dpsName, options, templateIdToPartnerId)) { }

private static AndroidJavaObject CreateInstance(UsercentricsOptions options, IDictionary<string, string> templateIdToPartnerId)
{
var usercentricsOptions = new AndroidJavaObject(ClassUsercentricsOptions, options.SettingsId);
return new AndroidJavaObject(ClassUsercentricsAdapter, usercentricsOptions, templateIdToPartnerId.DictionaryToMap());
}
public UsercentricsAdapter(UsercentricsOptions options, IDictionary<string, string> templateIdToPartnerId = null) : base(CreateInstance(options, templateIdToPartnerId)) { }

private static AndroidJavaObject CreateInstance(string dpsName, UsercentricsOptions options, IDictionary<string, string> templateIdToPartnerId)
private static AndroidJavaObject CreateInstance(UsercentricsOptions options, IDictionary<string, string> templateIdToPartnerId = null)
{
var usercentricsOptions = new AndroidJavaObject(ClassUsercentricsOptions, options.SettingsId);
return new AndroidJavaObject(ClassUsercentricsAdapter, usercentricsOptions, templateIdToPartnerId.DictionaryToMap(), dpsName);
var nativeOptions = new AndroidJavaObject(ClassUsercentricsOptions);

if (!string.IsNullOrEmpty(options.RulesetId))
{
nativeOptions.Call(FunctionSetRulesetId, options.RulesetId);;
LogController.Log($"{Tag} Setting RulesetID: {options.RulesetId}, SettingsId will be ignored", LogLevel.Verbose);
}

if (!string.IsNullOrEmpty(options.SettingsId) && string.IsNullOrEmpty(options.RulesetId))
{
nativeOptions.Call(FunctionSetSettingsId, options.SettingsId);
LogController.Log($"{Tag} Setting SettingsId: {options.SettingsId}", LogLevel.Verbose);
}

if (!string.IsNullOrEmpty(options.DefaultLanguage))
{
nativeOptions.Call(FunctionSetDefaultLanguage, options.DefaultLanguage);
LogController.Log($"{Tag} Setting DefaultLanguage: {options.DefaultLanguage}", LogLevel.Verbose);
}

if (!string.IsNullOrEmpty(options.Version))
{
nativeOptions.Call(FunctionSetVersion, options.Version);
LogController.Log($"{Tag} Setting Version: {options.Version}", LogLevel.Verbose);
}

if (options.TimeoutMilliseconds.HasValue)
{
nativeOptions.Call(FunctionSetTimeoutMillis, options.TimeoutMilliseconds.Value);
LogController.Log($"{Tag} Setting TimeoutMilliseconds: {options.TimeoutMilliseconds}", LogLevel.Verbose);
}

if (options.ConsentMediation.HasValue)
{
nativeOptions.Call(FunctionSetConsentMediation, options.ConsentMediation.Value);
LogController.Log($"{Tag} Setting ConsentMediation: {options.ConsentMediation}", LogLevel.Verbose);
}

if (options.LoggerLevel.HasValue)
{
using var enumClass = new AndroidJavaClass(EnumUsercentricsLoggerLevel);
using var value = options.LoggerLevel.Value switch
{
UsercentricsLoggerLevel.None => enumClass.GetStatic<AndroidJavaObject>(UsercentricsLoggerLevelNone),
UsercentricsLoggerLevel.Error => enumClass.GetStatic<AndroidJavaObject>(UsercentricsLoggerLevelError),
UsercentricsLoggerLevel.Warning => enumClass.GetStatic<AndroidJavaObject>(UsercentricsLoggerLevelWarning),
UsercentricsLoggerLevel.Debug => enumClass.GetStatic<AndroidJavaObject>(UsercentricsLoggerLevelDebug),
_ => enumClass.GetStatic<AndroidJavaObject>(UsercentricsLoggerLevelNone),
};

nativeOptions.Call(FunctionSetLoggerLevel, value);
LogController.Log($"{Tag} Setting LoggerLevel: {options.LoggerLevel}", LogLevel.Verbose);
}

if (options.NetworkMode.HasValue)
{
using var enumClass = new AndroidJavaClass(EnumUsercentricsNetworkMode);
using var value = options.NetworkMode.Value switch
{
NetworkMode.World => enumClass.GetStatic<AndroidJavaObject>(UsercentricsNetworkModeWorld),
NetworkMode.EU => enumClass.GetStatic<AndroidJavaObject>(UsercentricsNetworkModeEU),
_ => enumClass.GetStatic<AndroidJavaObject>(UsercentricsNetworkModeWorld),
};

nativeOptions.Call(FunctionSetNetworkMode, value);
LogController.Log($"{Tag} Setting LoggerLevel: {options.NetworkMode}", LogLevel.Verbose);
}

return new AndroidJavaObject(ClassUsercentricsAdapter, nativeOptions, templateIdToPartnerId.DictionaryToMap());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "com.chartboost.consent.usercentrics",
"name": "Chartboost.Core.Consent.Usercentrics",
"rootNamespace": "Chartboost.Core.Usercentrics",
"references": [
"com.chartboost.core"
"Chartboost.Core",
"Chartboost.Logging"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
8 changes: 8 additions & 0 deletions Runtime/Core/NetworkMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Chartboost.Core.Usercentrics
{
public enum NetworkMode
{
World = 0,
EU = 1
}
}
11 changes: 11 additions & 0 deletions Runtime/Core/NetworkMode.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d19177f

Please sign in to comment.