Installation and initialization

AppMetrica Push Cordova is a plugin for the Cordova (PhoneGap) platform that includes support for the AppMetrica Push SDK for Android and iOS through the JavaScript interface.

Before using the AppMetrica Push Cordova plugin, you need to enable and initialize the AppMetrica Cordova plugin version 0.2.0 or later.

  1. Integrating the plugin
  2. Connection examples
  3. API methods

Integrating the plugin

Step 1. Add the supported platforms to your project

Step 2. Add the plugin to the project by using one of the following console commands:
cordova plugin add yandex-appmetrica-push-plugin-cordova
Copied to clipboard
cordova plugin add
Copied to clipboard

When you add another supported platform to the project, the plugin automatically downloads the corresponding SDK library.

Step 3. (For Android projects only) Add the following to the application element of the AndroidManifest.xml file:

<meta-data android:name="ymp_gcm_project_number" android:value="number:SENDER_ID"/>
Copied to clipboard
For example:
  1. Add the cordova-custom-config plugin:
    cordova plugin add cordova-custom-config
    Copied to clipboard
  2. Make the following changes to the config.xml file of the android project:
    <config-file parent="./application" target="AndroidManifest.xml">
      <meta-data android:name="ymp_gcm_project_number" android:value="number:SENDER_ID" />
    Copied to clipboard
What is SENDER_ID?

SENDER_ID — Unique app identifier in GCM (Google Cloud Messaging).

Connection examples

In the example below:

  • The JavaScript object with the configuration is created.
  • The AppMetrica Cordova plugin is activated.
  • The AppMetrica Push Cordova plugin is initialized.
  • The push token of the device is output to the log.
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady () {
  var configuration = {
    apiKey: 'Your API key here'
  window.appMetricaPush.getToken(function (token) {
    console.log("Token: " + token);
Copied to clipboard
What is the API key?

The API key is a unique application identifier that is issued in the AppMetrica web interface during