Installation and initialization
Support and development of the plugin has been stopped. We do not guarantee the SDK will work correctly.
AppMetrica Cordova is a plugin for the Cordova (PhoneGap) platform. It includes support for the AppMetrica SDK for Android and iOS via the Javascript interface.
Step 1. Integrate the AppMetrica Cordova plugin
- Add the supported platforms to your project
- Add the plugin to the project by using one of the following console commands:
cordova plugin add yandex-appmetrica-plugin-cordova
Copied to clipboardor
cordova plugin add https://github.com/yandexmobile/metrica-plugin-cordova.git
Copied to clipboardWhen you add another supported platform to the project, the plugin automatically downloads the corresponding SDK library.
Step 2. Initialize the library
An example of initializing the library:
document.addEventListener('deviceready', onDeviceReady, false); function onDeviceReady () { // Creating an extended library configuration. var configuration = { // Mandatory. apiKey: 'Your API key', // Optional. locationTracking: true, handleFirstActivationAsUpdate: true, sessionTimeout: 15 } // Initializing the AppMetrica SDK. window.appMetrica.activate(configuration); // Sending a custom event. window.appMetrica.reportEvent('Test event', { 'foo': 'bar' }); }
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.
Example of a project with the integrated AppMetrica SDK on GitHub.
Step 3. (Android) Connect the Play Install Referrer library
Connecting the library Play Install Referrer is mandatory. It is used to track the installation source.
dependencies { ... implementation 'com.android.installreferrer:installreferrer:1.1.2' }
Copied to clipboard
If there is no build-extras.gradle , create it using the instruction.