Improving targeting
ITargetingProxy provides few global configuration options.
Sdk property of Appstock can be used to get the instance of ITargetingProxy.
Data-driven approach
TargetingData is a data container -- with a SerializableAttribute -- for specifying settings via Unity Editor.
External User IDs
If you happen to know external ID of this user on other services, you can add them as ExternalUserID elements.
Warning
If you populate ext, make sure it is a valid JSON object.
Other JSON value types are NOT supported.
Applying the data
- Expose TargetingData variable on your MonoBehaviour
- Or put it inside some ScriptableObject and assign through that.
- Call extension method Apply(ITargetingProxy, TargetingData) on Appstock.Sdk and pass your TargetingData.
#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);
Debug.Log($"[{DateTime.Now:O}] Attempting to init SDK...");
Appstock.InitializeSdk("appstock-demo");
Debug.Log($"[{DateTime.Now:O}] Letting SDK init to finish...");
yield return new WaitForSeconds(1);
Debug.Log($"[{DateTime.Now:O}] Applying targeting data...");
Appstock.Targeting.Apply(targetingData);
Tip
You can find a complete code in "ConfigAndTargeting" sample.
Ext Slots
Some data structures expose public fields of type ExtSlot.
See Ext Slot page for more info.
Taking a snapshot of active data
Extension method TakeSnapshot(ITargetingProxy) can retrieve all readable properties from ITargetingProxy.
var targetingSnapshot = Appstock.Targeting.TakeSnapshot();
It can be serialized and logged into console
var snapshotJson = JsonUtility.ToJson(targetingSnapshot, prettyPrint: true);
Debug.Log($"(snapshot) {snapshotJson}");
or compared to the expected data -- to log differences for later manual inspection.
var unequalFields = targetingData.UnequalFields(targetingSnapshot, fieldsToIgnore: new[]
{
nameof(targetingData.userExtJson) // the ordering is not guaranteed upon retrieval
}).ToList();
if (unequalFields.Any())
{
var configJson = JsonUtility.ToJson(targetingData, prettyPrint: true);
Debug.Log($"(config) {configJson}");
Debug.LogWarning($"[DIFF-FIELDS] ({unequalFields.Count}): {string.Join(", ", unequalFields)}.");
}
else
{
Debug.Log("Targeting data applied successfully.");
}