Search Results for

Show / Hide Table of Contents

# SDK Configuration

ISdkProxy provides few global configuration options.

Sdk property of Appstock can be used to get the instance of ISdkProxy.

##### Warning

ISdkProxy::ExternalUserIds and SdkConfig::externalUserIds expose a potentially-deprecated property of native SDK library.

ITargetingProxy::ExternalUserIds / TargetingData::externalUserIds should be used instead in most cases.

See Improving targeting / External User IDs.

## Data-driven approach

SdkConfig is a data container -- with a SerializableAttribute -- for specifying settings via Unity Editor.

### Applying the config

- Expose SdkConfig variable on your MonoBehaviour
  - Or put it inside some ScriptableObject and assign through that.
- Call extension method Apply(ISdkProxy, SdkConfig) on Appstock.Sdk and pass your SdkConfig.

    #nullable enable

    namespace AppstockSDK.DevApp
    {
        public class TargetingDemo : MonoBehaviour
        {
            public SdkConfig sdkConfig = new();
            public TargetingData targetingData = new();

            // Start is called before the first frame update
            private IEnumerator Start()
            {
                Debug.Log($"[{DateTime.Now:O}] Applying config...");
                Appstock.Sdk.Apply(sdkConfig);

##### Tip

You can find a complete code in "ConfigAndTargeting" sample.

## Taking a config snapshot

SdkConfigSnapshot can retrieve all readable properties from ISdkProxy.

    var sdkConfigSnapshot = new SdkConfigSnapshot(Appstock.Sdk);

It can be serialized and logged into console

    var snapshotJson = JsonUtility.ToJson(sdkConfigSnapshot, prettyPrint: true);
    Debug.Log($"(snapshot) {snapshotJson}");

or compared to the expected config -- to log differences for later manual inspection.

    var unequalFields = sdkConfigSnapshot.UnequalFields(sdkConfig).ToList();
    if (unequalFields.Any())
    {
        var configJson = JsonUtility.ToJson(sdkConfig, prettyPrint: true);
        Debug.Log($"(config) {configJson}");
        Debug.LogWarning($"[DIFF-FIELDS] ({unequalFields.Count}): {string.Join(", ", unequalFields)}.");
    }
    else
    {
        Debug.Log("SDK config applied successfully.");
    }