Installing User Hook For Unity

The official User Hook Unity SDK combines both the iOS and the Android SDKs into a unitypackage file that can be imported into your Unity project. Once you follow the steps below you, your app will be connected to the User Hook platform.

Setup Application

Before integrating User Hook into your Unity application, be sure you have logged into the User Hook Admin page and created your account. You will need to know your App Id and App Key while installing the Unity SDK.

Download SDK

Once you have downloaded the pacakge, import it into your project by clicking on “Assets > Import Pacakge > Custom Package” and selecting the UserHook.unitypackage file from your computer.

The package contains three main folders.

  • Plugins - contains all the native iOS and Android files needed by User Hook
  • UserHook - Unity files written in C#
  • UserHookDemo - a demo Unity scene to show examples of using User Hook features inside Unity (optional)

Initialize User Hook

User Hook needs to be initialized once your app opens. To do this, you will need to add the UserHook prefab, located in the Assets/UserHook folder, to you your initial scene. You will only need to add User Hook to your initial scene. Once the initialization process is complete, you will be able to access the UserHook from all scenes in your app.

Once the prefab has been loaded, you need to adjust the execution order of the User Hook script to make sure it initializes early in the launch process. Click on “Edit > Project Settings > Script Execution Order” and make sure the UserHook script is at the top of the execution list.

Enter User Hook App Id and App Key

Once the User Hook unitypackage is installed, there will be a new top menu item called “User Hook”. Click on “User Hook > Enter App Id and App Key”. A window will pop-up and have fields for you to enter your User Hook App Id and App Key that you created on the User Hook Admin page. After entering your app id and app key, close out of the pop-up window.

After entering your app information, a new file will be created at “Resources/userhook.txt” that contains your app id and app key. This file is required for User Hook to work properly, do not delete it.

User Hook in the Unity Editor

User Hook will only work on an iOS or Android device. While running your app inside the Unity Editor, you will not be able to test features of User Hook like in-app messages or push notifications.

Exporting to iOS

After exporting your app as an iOS project, you will need to make a change to the Xcode build settings. Inside Xcode, click on “Build Settings”, find the entry for “Enable Objective-C Exceptions” and set the value to “Yes”. Now you may run your app on an iOS device.

Feedback Attachments for iOS

If your account allows image attachments to be uploaded with user feedback, you will need to add the proper privacy permission to your app plist file. iOS 10 and above require apps to request special permissions for apps to access a user’s photo library. Without this permission, a user will not be able to select an image file to upload.

The source version of this entry looks like:

<plist version="1.0">
<dict>
...

 <key>NSPhotoLibraryUsageDescription</key>
 <string>This app needs to access your photos</string>

...
</dict>
</plist>

You will also need to add the “Photos” framework to your Xcode project. Inside Xcode, click on “Build Phases” and expand the section for “Link Binary With Libraries”. Click the “+” button at the bottom of the section and add the “Photos.framework” to your project.

Exporting to Android

Before exporting to Android, you will need to click on “User Hook > Prepare for Android Build”. This finalizes a few Android configuration files needed by User Hook. Your app is now ready to run on Android devices.

Any time you update the Android package name for your app, you will need to run User Hook > Prepare for Android Build before exporting your APK.

User Hook will use a custom Application and Activity class for Android apps. These classes are referenced in the Assets/Plugins/Android/AndroidManifest.xml file. If your app already uses a custom Application or Activity file, you may need to modify the AndroidManifest file. The source files for the custom User Hook Application and Activity classes can be found in our GitHub userhook-sdk-android repo.

Done

That’s it. User Hook is now setup and will begin tracking user sessions.

If you will be using push notifications through User Hook, please reference the instructions for configuring iOS Push Notifications and Android Push Notifications for Unity.