- The first step would be to clone this repo in your ionic project root directory. To do that you need to run following command in terminal or in git bash.
git clone https://github.com/cloonegit/hms-analytics.git
- Add the plugin
ionic cordova plugins add hms-analytics
- In your ionic project build.gradle (inside platform/android), add
buildscript {
repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.huawei.agconnect:agcp:1.0.0.300'
}
}
...
- Add agconnect-services.json file inside platform/android/app
- To apply the plugin, add following code
declare var cordova: any;
let packageId = 'xxx.xxxxxx.xxxxx';
let pageName = 'Home';
let eventName = 'Home';
let eventData = {
'key': 'value'
};
cordova.plugins.HmsAnalytics.logEvent(
packageId, pageName, eventName, eventData,
(data) => { console.log(data) },
(err) => { console.log(err) }
);