@deltax-sdk/ionic-deltax-mobile-sdk v1.0.3
DxMobileSdk
Description
DxMobileSdk is an angular service which acts as an interface to @deltax-sdk/cordova-plugin-deltax-mobile-sdk. It is compatible with ionic 3+ applications built on angular.
Usage
Installation:
First, install cordova-plugin-deltax-mobile-sdk by running one of the following commands (depending on the ionic version):
ionic cordova plugin add @deltax-sdk/cordova-plugin-deltax-mobile-sdk
OR
cordova plugin add @deltax-sdk/cordova-plugin-deltax-mobile-sdk
Then install the DxMobileSdk wrapper:
npm install --save @deltax-sdk/ionic-deltax-mobile-sdk
Next, add DxMobileSdk as a provider in your NgModule declaration (for example, in src/app/app.module.ts
):
import { DxMobileSdk } from '@deltax-sdk/ionic-deltax-mobile-sdk/DxMobileSdk';
@NgModule({
declarations: [
// ...
],
imports: [
// ...
],
bootstrap: [IonicApp],
entryComponents: [
// ...
],
providers: [
// ...
, DxMobileSdk
]
})
export class AppModule {}
Initialize the plugin (ideally, in app.component.ts constructor on platform ready, as follows) :
import { DxMobileSdk } from '@deltax-sdk/ionic-deltax-mobile-sdk/DxMobileSdk';
import { Platform } from 'ionic-angular';
export class MyApp {
constructor(private platform : Platform, private dxPlugin: DxMobileSdk ) {
this.platform.ready().then( async () => {
await this.dxPlugin.initPlugin();
});
}
//...
}
Note: It is necessary to wait for a dxPlugin method call to end before making another dxPlugin method call in order to avoid unintended consequences. For example, if trackEvent is called before initDxTracker has completed execution, then the sdk might not have initialized the tracker for the particular business profile, and it might throw an error. We recommend using async await to avoid promise hell.
Finally, inject it into any of your components or pages:
import { DxMobileSdk } from '@deltax-sdk/ionic-deltax-mobile-sdk/DxMobileSdk';
export class MyApp {
constructor(private dxPlugin: DxMobileSdk ) { }
//...
var params:any = {};
params.Stage1 = '5';
params.Stage2 = '10.3';
params.GoalId = '6AMDV2';
this.dxPlugin.trackEvent(params, 'xxxx1234').then(
( ) => {
//Statements to execute on success
},
(err) => {
//Statements to execute on error
}
);
}
Methods | Description |
---|---|
initPlugin( ) => Promise(void, Error) | Returns a promise that resolves when the plugin is initialised |
initDxTracker(businessProfileEncodedId : string, setDefault? : boolean) => Promise(void, Error) | Returns a promise that resolves when the tracker is initialized for the given businessProfileEncodedId. If setDefault is passed and it is true, the initialized tracker will also be set as default tracker |
setDefaultInstance(businessProfileEncodedId : string) => Promise(void, Error) | Returns a promise that resolves when the existing tracker for the businessProfileEncodedId is set as default tracker |
setCustomerEmail(email : string, businessProfileEncodedId? : string, isEncoded? : boolean) => Promise(void, Error) | Returns a promise that resolves when the default customer email is set. If businessProfileEncodedId is passed, the default customer email is set for that particular tracker instance. Else, default customer email is set for the default tracker instance. If isEncoded is passed and it is true, the tracker expects an encoded value for customer email. By default, the tracker encodes the given customer email before the event is tracked |
setCustomerPhoneNumber(phoneNumber : string, businessProfileEncodedId? : string, isEncoded? : boolean) => Promise(void, Error) | Refer to setCustomerEmail method description |
setCustomerId(id : string, businessProfileEncodedId? : string) => Promise(void, Error) | Returns a promise that resolves when the default customer id is set. If businessProfileEncodedId is passed, the default customer email is set for that particular tracker instance. Else, default customer email is set for the default tracker instance |
trackEvent(params : any, businessProfileEncodedId? : string) => Promise(void, Error) | Returns a promise that resolves when the event has been successfully tracked. Refer to Event Parameters section for supported properties in params object |
enableTracking( ) => Promise(void, Error) | Returns a promise that resolves when tracking is enabled in the SDK |
disableTracking( ) => Promise(void, Error) | Returns a promise that resolves when tracking is disabled in the SDK |
trackClick(uri : string, businessProfileEncodedId? : string) => Promise(void, Error) | Returns a promise that resolves when a deep link click event is tracked for the given URI string |
Event Parameters
The first parameter of the trackEvent method is an object which supports the following properties with string values. Any of these properties which are set will be passed in the event which is tracked.
- TransactionId
- CurrencyCode
- TransactionValue
- Quantity
- CustomerId
- CustomerMail
- CustomerPhone
- GoalId
- Stage1
- Stage2
- Stage3
- Stage4
- Stage5
- Stage6
- Stage7
- Stage8
- Stage9
- Stage10
- XCart
Refer to cordova-plugin-deltax-mobile-sdk for detailed documentation.