---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://yandex.com/support/appmetrica-io/en/sdk/unity/push/quick-start.md
  - https://yandex.com/support/appmetrica-io/ru/sdk/unity/push/quick-start.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/support/appmetrica-io/en/llms.txt

# Installation and initialization

AppMetrica Push Unity is a plugin for the [Unity3d](http://docs.unity3d.com/) game platform that includes support for the AppMetrica Push SDK for the Android and iOS platforms.

This section describes the steps to enable and initialize the AppMetrica Unity Plugin:

## Step 1. Enable the AppMetrica Unity plugin {#integration-appmetrica}

To enable the AppMetrica Unity plugin, follow the [instructions](https://yandex.com/support/appmetrica-io/en/sdk/unity/analytics/quick-start.md).

{% note info %}

You must use the AppMetrica Unity plugin version 6.1.0 or higher.

{% endnote %}

## Stage 2. Enable the AppMetrica Push Unity plugin {#integration}

The plugin is enabled via the [Unity Package Manager](https://docs.unity3d.com/Manual/Packages.html).

Add the following dependencies to [Packages/manifest.json](https://docs.unity3d.com/Manual/upm-manifestPrj.html):

```json translate=no
{
  "dependencies": {
    "io.appmetrica.analytics.push": "https://github.com/appmetrica/push-unity-plugin.git#v2.0.0"
  }
}
```

## Step 3. Initialize the library {#activate}

You should activate AppMetrica Push using the [RuntimeInitializeOnLoadMethodAttribute](https://docs.unity3d.com/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html) attribute.

Create a static method with the `[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]` attribute and activate AppMetricaPush using the `AppMetricaPush.Activate()` method.

> Example:
>
> ```csharp translate=no
> using Io.AppMetrica;
> using Io.AppMetrica.Push;
> using UnityEngine;
>
> public static class AppMetricaActivator {
>     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
>     private static void Activate() {
>         AppMetrica.Activate(new AppMetricaConfig("APIKey"));
>         AppMetricaPush.Activate();
>     }
> }
> ```

{% note info %}

You must call `AppMetricaPush.Activate()` strictly after `AppMetrica.Activate()`.

{% endnote %}

## Stage 4. Add settings for each native platform {#platforms}

{% list tabs %}

- Android

  1. [Set up](https://yandex.com/support/appmetrica-io/en/sdk/android/push/android-settings.md#firebase) the app for using Firebase. [Get and add to AppMetrica](https://yandex.com/support/appmetrica-io/en/sdk/android/push/android-settings.md#firebase-key) a server key for using Firebase Cloud Messaging.
  2. To configure AndroidManifest.xml, make changes to the `application` element in `AndroidManifest.xml`:

     ```xml translate=no
     <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](https://console.firebase.google.com/): 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](https://console.firebase.google.com/): go to **Project settings**&nbsp;→ **Cloud Messaging** and copy the value of the **Sender ID** field.


     `API_KEY` — App key in Firebase. You can find it in the `current_key` field of the `google-services.json` file. You can download the file in the [Firebase console](https://support.google.com/firebase/answer/7015592).


     `PROJECT_ID` — App ID in Firebase. You can find it in the `project_id` field of the `google-services.json` file. You can download the file in the [Firebase console](https://console.firebase.google.com/).


- iOS

  1. Add the SSL certificate to AppMetrica according to the [instructions](https://yandex.com/support/appmetrica-io/en/sdk/ios/push/ios-settings.md).
  2. To receive push notifications, ask the user for permission. We recommend using the [Mobile Notifications](https://docs.unity3d.com/Packages/com.unity.mobile.notifications@2.0/manual/index.html) Unity package and request permission according to the [instructions](https://docs.unity3d.com/Packages/com.unity.mobile.notifications@2.0/manual/iOS.html#authorization-request).

  {% note info %}

  The AppMetrica Push Unity plugin uses <q>swizzling</q>: it intercepts the execution of certain methods of the `UnityAppController` class by using the ObjectiveC runtime. You can find the source code of the swizzling mechanism in the [AMPUAppMetricaPushAppController.m](https://github.com/appmetrica/push-unity-plugin/blob/main/Runtime/Plugins/iOS/AMPUAppMetricaPushAppController.m) file.

  {% endnote %}

{% endlist %}

### See also

- [Configuring an Android application to send push notifications](https://yandex.com/support/appmetrica-io/en/sdk/android/push/android-settings.md)
- [Configuring an iOS application to send push notifications](https://yandex.com/support/appmetrica-io/en/sdk/ios/push/ios-settings.md)
- [Launching a push campaign](https://yandex.com/support/appmetrica-io/en/push/marketing.md)

<!-- source: en/_includes/feedback-button-3.md -->
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.

<a href="../../../troubleshooting/feedback-new">
  <span class="button">Contact support</span>
</a>

<a href="../../../troubleshooting/feedback-docs">
  <span class="button">Suggest an improvement for documentation</span>
</a>
<!-- endsource: en/_includes/feedback-button-3.md -->
