Installation and initialization
AppMetrica Push Unity is a plugin for the Unity3d game platform that includes support for the AppMetrica Push SDK for the Android and iOS platforms.
Before using the AppMetrica Push Unity plugin, you need to enable and initialize the AppMetrica Unity plugin version 4.0.0 or later.
Alert
To update the plugin, delete the Assets/AppMetricaPush
directory and import the new plugin version (pay attention to the Android configuration).
Integrating the plugin
Note
The plugin uses the External Dependency Manager for Unity to resolve dependencies.
Step 1. Download the AppMetrica Push Unity plugin.
Step 2. Add the plugin to the project — open the project in Unity Editor and import the AppMetricaPush.unitypackage
(Assets → Import Package → Custom Package).
Step 3. Open the Assets/AppMetricaPush/
folder and drag the AppMetrica
prefab to the project's main stage.
If the plugin is integrated this way, the AppMetricaPush script on the added prefab automatically initializes the AppMetrica Push SDK.
The added AppMetricaPush
prefab is a singleton. It isn't deleted when switching to a new Unity stage, and it deletes other objects that the AppMetricaPush
script is installed on.
Configuring the plugin
-
Add the SSL certificate to AppMetrica according to the instructions.
-
To receive push notifications, ask the user for permission. We recommend using the Mobile Notifications Unity package and request permission according to the instructions.
Note
The AppMetrica Push Unity Plugin uses swizzling
: it intercepts the execution of certain methods of the UnityAppController
class by using the ObjectiveC runtime. The code is in the AppMetricaPush/Plugins/iOS/YMPBridge.m
file.
-
Set up the app for using Firebase. Get and add to AppMetrica a server key for using Firebase Cloud Messaging:
-
To configure AndroidManifest.xml, make changes to the
application
element inAndroidManifest.xml
:<meta-data android:name="ymp_firebase_default_app_id" android:value="APP_ID"/> <meta-data android:name="ymp_gcm_default_sender_id" android:value="number:SENDER_ID"/> <meta-data android:name="ymp_firebase_default_api_key" android:value="API_KEY"/> <meta-data android:name="ymp_firebase_default_project_id" android:value="PROJECT_ID"/>
APP_ID
— ID of the app in Firebase. You can find it in the Firebase console: go to the Project settings. In the Your application section copy the value of the application ID field.SENDER_ID
— The unique ID of sender in Firebase. You can find it in the Firebase console: go to Project settings → Cloud Messaging and copy the value of the Sender ID field.API_KEY
— App key in Firebase. You can find it in thecurrent_key
field of thegoogle-services.json
file. You can download the file in the Firebase console.PROJECT_ID
— App ID in Firebase. You can find it in theproject_id
field of thegoogle-services.json
file. You can download the file in the Firebase console.Note
If you use the AppMetrica Push SDK integration sample, change the
package
attribute value in themanifest
element to thepackage id
of your application.There is an example of the file in the
Assets/AppMetricaPush/Plugins/Android/
directory (AndroidManifest.xml
).
See also
- Configuring an Android application to send push notifications
- Configuring an iOS application to send push notifications
- Launching a push campaign
If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.