Unity

Integration

Attention! Only Unity 5.4 and above is supported.

To integrate your application with devtodev system please perform the following actions:

  1. Add the application to the Space using the wizard for adding application. Attention! If your Unity project can be used for compilations for different platforms, you need to add the applications in devtodev for each platform. As a result, the statistics will be gained for each platform separately.

  2. Attention! If you install SDKs versions (1.*) 2.0, 2.0.1 or 2.0.2, you have to delete them before integrate the latest version.

    To do that, delete following files and catalogues:

    For 1.*

    - Assets/DevToDev/ (the folder) - Assets/Plugins/Android/ (files android-suport-v4.jar, AndroidManifest.xml, devtodev.jar, devtodev_android_wrapper.jar, google-play-services.jar) - Assets/Plugins/iOS/ (files AccrualType.h, CustomEventParams.h, all DevToDev*.h, Gender.h, libdevtodev.a, ReceiptStatus.h, SocialNetwork.h, TimeStatus.h, TutorialState.h) - Assets/Plugins/Metro/devtodev.dll

    For 2.0 - Assets/devtodev (the folder) - Assets/Plugins/DevToDevOSX.bundle

    After deleting, unpack devtodev.unitypackage version 2.1 and replace all the files. If you used an ​interface integration, you have to re-integrate SDK.

  3. Unpack the devtodev.unitypackage into the project

  4. There are 2 types of integration available:

    In the interface.

    • Open the main screen of the app.

    • Open Window/devtodev menu, then you'll see the following window:

  • Switch "Analytics" on by pressing "On" button

  • Add AppKey and SecretKey for all the using platforms (you can select the platform by clicking on it). If you need to debug, switch logging on.

    App ID and Secret key can be found in the application settings (Open "My apps" → App Name → "Settings" → "Integration").

  • Script with all needed parameters if SDK initialization and tracking the user session will be automatically created and added to the scene.

Using code. Add the following strings to the GameObject which will be on the scene during the whole cycle of application work:

public class YourBehaviourScript : MonoBehaviour
{
void Start() 
{
#if UNITY_ANDROID
// <param name="androidAppId"> devtodev App ID for Google Play version of application </param>
// <param name="androidAppSecret"> devtodev Secret key for Google Play version of application </param>
   DevToDev.Analytics.Initialize(string androidAppId, string androidAppSecret);
#elif UNITY_IOS
// <param name="iosAppId"> devtodev App ID for App Store version of application </param>
// <param name="iosAppSecret"> devtodev Secret key for App Store version of application </param>
   DevToDev.Analytics.Initialize(string iosAppId, string iosAppSecret);
#elif UNITY_WEBGL
// <param name="webglAppId"> devtodev App ID for Web version of application </param>
// <param name="webglAppKey"> devtodev Secret key Web version of application </param>
   DevToDev.Analytics.Initialize(string webglAppId, string webglAppSecret);
#elif UNITY_STANDALONE_WIN
// <param name="winAppId"> devtodev App ID for Windows Store version of application </param>
// <param name="winAppSecret"> devtodev Secret key for Windows Store version of application </param>
   DevToDev.Analytics.Initialize(string winAppId, string winAppSecret);
#endif
}
};

The appId and appSecret values are unique for each app on each platform and can be found in the settings of appropriate app (My apps -> App Name -> Settings -> Integration).

The specificity of integration on iOS platform

If you are planning to build an app for iOS, you need to add libz.tbd to the XCode project settings. This library is used by devtodev Unity SDK to compress data sent to devtodev servers. Also you have to to add UserNotifications.framework as an optional library.

Additional initialization

If the application you integrate SDK in is a part of cross-platform project, then the user data initialization is required.

Since the analytics of cross-platform projects is based on an unique user (unlike the usual projects where it is based on device identifiers), you have to:

  • Set the unique cross-platform user identifier (it will be used for cross-platform project data collection).

  • Actualize the user data. Mostly it is about game applications where the player has a game level as a characteristic. For such projects you need to set the current player level.

We recommend you to set the user identifier before SDK initialization, otherwise the user identifier from the previous session will be used since the SDK initialization moment till the UserID property is set.

If your cross-platform application supposes to be used without cross-platform authorization, don't use the UserID property or use the empty string ("") as the user identifier. SDK will assign the unique identifier to user. This identifier will we used until the real cross-platform identifier assigns to the user.

/// <summary> Property allows to initialize the user. 
/// It applies when SDK initialization or user relogin.</summary>
/// <param name="activeUserId">unique cross-platform user identifier (max. 64 symbols)</param>
DevToDev.Analytics.UserId = activeUserID;

/// <summary> Method sets the current user level. 
/// Using this method allows to actualize the SDK user data in game cross-platform applications.</summary>
/// <param name="level">number of current game level of the user</param>
DevToDev.Analytics.CurrentLevel(level);

/// <summary>  Property allows to set current application version.
/// Attention! This property is necessary for WEB and Windows Standalone apps only.
/// It will be ignored on other platforms.</summary>
/// <param name="version"> current version of your application</param>
DevToDev.Analytics.ApplicationVersion = version;

/// <summary> devtodev App Id and Secret key can be found in the devtodev application
/// settings page (“My apps” → App Name → “Settings” → “Integration”) </summary>
DevToDev.Analytics.Initialize(string appId, string appSecret);

Attention! If your application allows user to relogin (changing the user during the working session of application), then the UserID property and CurrentLevel method should be called just after the authorization. You don't need to call the SDK initialization one more time.

Debug mode

To enable the debug mode and make SDK notifications displayed in the console use this method:

/// <summary> Enable/Disable log</summary>
/// <param name="isEnabled">Enabled/Disabled log</param>
DevToDev.Analytics.SetActiveLog(bool isEnabled);

Collecting data about the amount of sessions and their length

Attention! The data about the amount of sessions and their length is collected automatically by default. In case you want to control the beginning and the end of a session manually, use the methods below: For the start of the session use the StartSession method:

//Call this when the session starts or is resumed
DevToDev.Analytics.StartSession();

For the end of the session use the EndSession method:

//Call this when the session is completed
DevToDev.Analytics.EndSession();

Delivering your application to the Mac App Store

  1. Read an article and make sure you follow all the recommendations.

  2. Delete a meta file from DevToDevOSX.bundle:

    File.Delete (projPath + "/Contents/Plugins/DevToDevOSX.bundle/Contents.meta");
  3. Rename CFBundleIdentifier in Info.plist inside the devtodev plugin, for example:

    string plistPath = appPath + "/Contents/Plugins/DevToDevOSX.bundle/Contents/Info.plist";
    PlistDocument plist = new PlistDocument ();
    plist.ReadFromString (File.ReadAllText (plistPath));
    plist.root.SetString ("CFBundleIdentifier", PlayerSettings.applicationIdentifier + ".devtodev");
    File.WriteAllText (plistPath, plist.WriteToString ());
  4. Sign the DevToDevOSX.bundle with the .entitlements you created earlier. To do this, type the following into the macOS Terminal:

    codesign -f --deep -s 'Mac Developer: Developer Name' --entitlements "yourapp.entitlements" "path/to/your.app/Contents/Plugins/DevToDevOSX.bundle"

Last updated