Installation and initialization
Support and development of the plugin has been stopped. We do not guarantee the SDK will work correctly.
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.
Integrating the plugin
Step 1. Add the supported platforms to your project
orcordova plugin add yandex-appmetrica-push-plugin-cordova
Copied to clipboard
cordova plugin add https://github.com/yandexmobile/metrica-push-plugin-cordova.git
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
- Add the
cordova-custom-config
plugin:cordova plugin add cordova-custom-config
Copied to clipboard - 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" /> </config-file>
Copied to clipboard
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.appMetrica.activate(configuration); window.appMetricaPush.init(); window.appMetricaPush.getToken(function (token) { console.log("Token: " + token); }); }
Copied to clipboard
The API key is a unique application identifier that is issued in the AppMetrica web interface during app registration.
Make sure you have entered it correctly.
API methods
In the code, use window.appMetricaPush
for accessing AppMetrica Push.
init()
init()
Copied to clipboard
Initializes the AppMetrica Push Cordova plugin.
getToken()
getToken(function (token) { // Token has the String type. })
Copied to clipboard
Returns the push token of the device.