To add cordova plugin execute following command:
$ ionic cordova plugin add cordova-plugin-emma-sdk --variable ADD_PUSH=1
In file src/app/app.component.ts
append following code:
declare var window: any;
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private alertCtrl: AlertController
) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.initEMMA();
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
initEMMA() {
document.addEventListener('onDeepLink', (event: any) => {
const url = event.url;
EMMA.handleLink(url);
});
document.addEventListener('onDeviceId', (event) => {
//event.deviceId
});
const EMMA = window.plugins.EMMA;
const configuration = {
sessionKey: '<emma key>',
debug: true
};
EMMA.startSession(configuration);
// Optional to track location
// EMMA.trackLocation();
// Enable push system
/*
const pushOptions = {
classToOpen: 'io.emma.cordova.exampleionic.MainActivity',
iconResource: 'notification'
};
EMMA.startPush(pushOptions);
*/
}
}
Check EMMA documentation where you can find EMMA Key
Firebase
to be able to use FCM. https://firebase.google.com/docs/android/setupFor the notification received in Android to have an image we have to add in the config.xml which will be the
notification icon used.
config.xml
<resource-file src="resources/android/notification/drawable-mdpi-notification.png" target="app/src/main/res/drawable-mdpi/notification.png" />
<resource-file src="resources/android/notification/drawable-hdpi-notification.png" target="app/src/main/res/drawable-hdpi/notification.png" />
<resource-file src="resources/android/notification/drawable-xhdpi-notification.png" target="app/src/main/res/drawable-xhdpi/notification.png" />
<resource-file src="resources/android/notification/drawable-xxhdpi-notification.png" target="app/src/main/res/drawable-xxhdpi/notification.png" />
<resource-file src="resources/android/notification/drawable-xxxhdpi-notification.png" target="app/src/main/res/drawable-xxxhdpi/notification.png" />
To activate the push it is necessary to add the configuration file google-services.json
from the firebase project to the file config.xml
config.xml
<!-- Google services JSON from Firebase -->
<resource-file src="google-services.json" target="app/google-services.json" />
To be able to receive the push it is necessary to add the following service inside the AndroidManifest of the application by adding the following code in the config.xml
file
config.xml
<config-file parent="/manifest/application" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
<service android:enabled="true" android:exported="false" android:name="io.emma.android.push.EMMAFcmMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</config-file>
To initialize the push in the App, it is necessary to call the startPush method once the deviceReady
event has been received within the app.component.ts
file.
To integrate attribution it is necessary to configure DeepLink and AppLink in the app.
In order for the app to open automatically when a DeepLink or AppLink is executed, it is necessary to add the following to the config.xml
config.xml
<config-file parent="./application/activity" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="${custom_scheme}" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="${custom_scheme}.powlink.io" android:scheme="https" />
</intent-filter>
</config-file>
$ {custom scheme} should be replaced by the chosen schema name. Usually the name chosen has to do with the name of the app.
Once this has been added in the configuration it is necessary to add the event in the main component. This method is where the logic to process the link is added.
this.platform.ready().then(() => {
document.addEventListener('onDeepLink', (event) => {
//process deeplink and applink
});
...
To activate the localization it is necessary to add the following permissions to the config.xml
<config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</config-file>
Once the location has been added, it can be activated with the EMMA.trackLocation()
method.
To activate the Push functionality you will only have to call the EMMA.startPush()
method in onDeviceReady
.
To integrate SKAdNetwork see the native documentation here.
To correctly configure this functionality we will use the same dependencies as the Powlink integration in the native SDK: https://developer.emma.io/es/ios/integracion-sdk#dependencies-1
Once the dependencies have been configured, it is necessary to add the event in the main component.
document.addEventListener('onDeepLink', (event: any) => {
const url = event.url;
EMMA.handleLink(url);
});