Integrate your Unity Android app with Localytics.
Once data is uploaded, it can't be deleted, so it's a good idea to create a test app
in Localytics and use it to perfect
your instrumentation. Then you can switch the app key to the production app.
-
In your Localytics
Dashboard, create a new
application and copy the application key.
-
Download the latest
version of the SDK.
-
Import the unitypackage into your project.
-
Locate Assets/Plugins/Android/AndroidManifest.xml and put your package name in
the manifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="YOUR.PACKAGE.NAME">
-
Insert your app key into the application meta-data.
<meta-data android:name="LOCALYTICS_APP_KEY" android:value="YOUR_APP_KEY"/>
-
Replace the permission name with your app’s package identifier.
<permission android:name="YOUR.PACKAGE.NAME.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="YOUR.PACKAGE.NAME.permission.C2D_MESSAGE" />
-
If you intend to use push notifications, additionally add your push project
ID.
It is important to leave the escaped space ("\ ") before
your project id. This forces the field to be compiles as a string instead of
an int. Without it, push will not work. As an example, you want
android:value="\ 123456" not
android:value="\123456" or
android:value="123456".
<meta-data android:name="LOCALYTICS_PUSH_PROJECT_ID" android:value="\ YOUR_PUSH_PROJECT_ID"/>
-
If you intend to use push notifications, find the
com.localytics.android.PushReceiver receiver and use your package name as the
category.
<category android:name="YOUR.PACKAGE.NAME" />
-
In any MonoBehaviour you can now call Localytics commands using the
static Localytics class. You
must use preprocessor directives as the scripts cannot be called from the
editor. Localytics will
automatically initiate when your app loads and you can call it at any
time.
#if !UNITY_EDITOR && UNITY_ANDROID
Localytics.LoggingEnabled = true;
Localytics.SessionTimeoutInterval = 15;
#endif
-
Test your app. Run your application in the simulator, or on a real device if
possible, and check your Localytics
Dashboard to see the data
being reported. Remember that the upload is only guaranteed when the session is
opened and closed, so any events you tag may not appear until your second
session.
Congratulations! You're integrated. Check out the data in your
Dashboard or get even more insights
when you start
tagging
events. Don't forget to test your app. Run it in an emulator, or on a real
device if possible.