-
Notifications
You must be signed in to change notification settings - Fork 0
Platform Extensions
Wrappers are used to add support for additional platforms should you need it. All events you send via Game Analytics will eventually reach the wrapper, which handles the actual sending of the event on a per-platform basis.
We are going to extend the SDK to support the imaginary console Playbox. First, we need to add a custom wrapper. Provided you have the Game Analytics SDK installed as a local package (i.e. you can make changes), you can add a custom wrapper by doing the following:
- Open
GA-SDK-Unity/Runtime/Scripts/Wrapper/GA_Wrapper.cs. On line 11, the one that starts with an#ifdirective, add&& !UNITY_PLAYBOXafter!UNITY_SAMSUNGTV. - Next to
GA_Wrapper, create a new C# file. Call itGA_PlayboxWrapper. - Paste the following:
using System.Runtime.InteropServices;
namespace GameAnalyticsSDK.Wrapper
{
public partial class GA_Wrapper
{
#if (UNITY_PLAYBOX) && (!UNITY_EDITOR)
[DllImport("__Internal")]
private static extern void configureAvailableCustomDimensions01(string list);
[DllImport("__Internal")]
private static extern void configureAvailableCustomDimensions02(string list);
[DllImport("__Internal")]
private static extern void configureAvailableCustomDimensions03(string list);
[DllImport("__Internal")]
private static extern void configureAvailableResourceCurrencies(string list);
[DllImport("__Internal")]
private static extern void configureAvailableResourceItemTypes(string list);
[DllImport("__Internal")]
private static extern void configureSdkGameEngineVersion(string unitySdkVersion);
[DllImport("__Internal")]
private static extern void configureGameEngineVersion(string unityEngineVersion);
[DllImport("__Internal")]
private static extern void configureBuild(string build);
[DllImport("__Internal")]
private static extern void configureUserId(string userId);
[DllImport("__Internal")]
private static extern void initialize(string gamekey, string gamesecret);
[DllImport("__Internal")]
private static extern void setCustomDimension01(string customDimension);
[DllImport("__Internal")]
private static extern void setCustomDimension02(string customDimension);
[DllImport("__Internal")]
private static extern void setCustomDimension03(string customDimension);
[DllImport("__Internal")]
private static extern void setGlobalCustomEventFields(string customFields);
[DllImport("__Internal")]
private static extern void addBusinessEvent(string currency, int amount, string itemType, string itemId, string cartType, string fields, bool mergeFields);
[DllImport("__Internal")]
private static extern void addResourceEvent(int flowType, string currency, float amount, string itemType, string itemId, string fields, bool mergeFields);
[DllImport("__Internal")]
private static extern void addProgressionEvent(int progressionStatus, string progression01, string progression02, string progression03, string fields, bool mergeFields);
[DllImport("__Internal")]
private static extern void addProgressionEventWithScore(int progressionStatus, string progression01, string progression02, string progression03, int score, string fields, bool mergeFields);
[DllImport("__Internal")]
private static extern void addDesignEvent(string eventId, string fields, bool mergeFields);
[DllImport("__Internal")]
private static extern void addDesignEventWithValue(string eventId, float value, string fields, bool mergeFields);
[DllImport("__Internal")]
private static extern void addErrorEvent(int severity, string message, string fields, bool mergeFields);
[DllImport("__Internal")]
private static extern void setEnabledInfoLog(bool enabled);
[DllImport("__Internal")]
private static extern void setEnabledVerboseLog(bool enabled);
[DllImport("__Internal")]
private static extern void setEnabledManualSessionHandling(bool enabled);
[DllImport("__Internal")]
private static extern void setEnabledEventSubmission(bool enabled);
[DllImport("__Internal")]
private static extern void gameAnalyticsStartSession();
[DllImport("__Internal")]
private static extern void gameAnalyticsEndSession();
[DllImport("__Internal")]
private static extern void setManualSessionHandling(bool enabled);
[DllImport("__Internal")]
private static extern void setEventSubmission(bool enabled);
private static string getRemoteConfigsValueAsString(string key, string defaultValue) => defaultValue;
private static bool isRemoteConfigsReady() => default;
private static string getRemoteConfigsContentAsString() => string.Empty;
private static string getABTestingId() => string.Empty;
private static string getABTestingVariantId() => string.Empty;
public static string getUserId() => string.Empty;
private static void configureAutoDetectAppVersion(bool flag) { }
#endif
}
}- Bla bla bla stuff about
GameAnalyics.Playboxplugin. - Reroute the Playbox platform to another.
Game Analytics has several features for gaming operations. Namely, it allows you to set up remote configs and A/B testing. If you want your wrapper to support this functionality, you can replace the default methods for it above with the following code:
[DllImport("__Internal")]
private static extern string getRemoteConfigsValueAsString(string key, string defaultValue);
[DllImport("__Internal")]
private static extern bool isRemoteConfigsReady();
[DllImport("__Internal")]
private static extern string getRemoteConfigsContentAsString();
[DllImport("__Internal")]
private static extern string getABTestingId();
[DllImport("__Internal")]
private static extern string getABTestingVariantId();
[DllImport("__Internal")]
public static extern string getUserId();
[DllImport("__Internal")]
private static extern void configureAutoDetectAppVersion(bool flag);You may want to debug your wrapper from within the editor. To do this, do the following:
- Select the
GameAnalytics.Playboxplugin, and underSelect platforms for pluginmake sureEditoris included. - At the top of both the
GA_WrapperandGA_PlayboxWrapperscripts, paste the following:
#define UNITY_PLAYBOX
#undef UNITY_EDITORMake sure to revert these changes after you are done! These settings should commonly not be used during development as they may cause weird behavior or fill the game analytics web interface with data gathered during development (i.e. useless data). If you are working in a large team, it is recommended to debug your wrapper on another branch altogether.