Initialization
This section outlines the steps to initialize the Trackier Cordova SDK in your Cordova or Ionic Native project, enabling tracking of user interactions, attribution, and campaign analytics. Initialization involves retrieving your SDK key (app token) from the Trackier Mobile Marketing Platform (MMP) Panel, configuring the SDK with the key and environment, and registering the provider for Ionic Native apps.
Prerequisites
- Trackier Cordova SDK installed in your project
- A Trackier MMP account with access to the Trackier Panel
- Cordova 9.0 or later
- For Ionic Native apps:
- Ionic CLI and Capacitor
@awesome-cordova-plugins/corepackage installed
- Basic knowledge of JavaScript, Angular (for Ionic Native), and Cordova development
Retrieve Your SDK Key
To initialize the AppTrove SDK, you need an SDK key (app token) from the Trackier MMP Panel.
Steps to Retrieve the SDK Key
- Log in to your Trackier MMP account.
- Select your application from the Dashboard.
- Navigate to SDK Integration via the left-side navigation menu.
- Copy the SDK Key to use as the
app_token.

Initialize the SDK
After installing the SDK, initialize it by configuring the TrackierConfig object with your SDK key and environment in your Cordova or Ionic Native application. The SDK automatically registers with Cordova's deviceready, resume, and pause events.
Step 1: Configure the SDK for Cordova/Ionic Native
- Open your main application file (e.g.,
index.jsfor Cordova ortab1.page.tsfor Ionic Native). - Import the required Trackier modules and initialize the SDK after the
devicereadyevent (Cordova) or in thengOnInitlifecycle hook (Ionic Native). - Set the environment to one of the following values based on your deployment stage:
TrackierEnvironment.DevelopmentTrackierEnvironment.ProductionTrackierEnvironment.Testing
JavaScript Example (Ionic Native)
import { Component } from '@angular/core';
import { TrackierCordovaPlugin, TrackierConfig, TrackierEnvironment } from '@awesome-cordova-plugins/trackier/ngx';
@Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page {
constructor(private trackierCordovaPlugin: TrackierCordovaPlugin) {}
async ngOnInit() {
/* While Initializing the SDK, you need to pass the SDK key and environment.
* The first argument is the AppTrove SDK key.
* The second argument is the environment: "development", "production", or "testing". */
var key = "0455721b-XXXX-XXXXX-596d818d910a"; // Replace with your SDK key
var trackierConfig = new TrackierConfig(key, TrackierEnvironment.Development);
// Set Android ID for enhanced tracking
trackierConfig.setAndroidId("User Android Id "); // Optional And For Android Only
this.trackierCordovaPlugin.initializeSDK(trackierConfig);
}
}
JavaScript Example (Pure Cordova)
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
var key = "0455721b-XXXX-XXXXX-596d818d910a"; // Replace with your SDK key
var trackierConfig = new TrackierConfig(key, TrackierEnvironment.Development);
TrackierCordovaPlugin.initializeSDK(trackierConfig);
}
Step 2: Register the Provider for Ionic Native
For Ionic Native apps, register the TrackierCordovaPlugin provider in the app module to enable dependency injection.
- Open the
app.module.tsfile in your Ionic project. - Import the
TrackierCordovaPluginand add it to theprovidersarray.
Example (app.module.ts)
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { TrackierCordovaPlugin } from '@awesome-cordova-plugins/trackier/ngx';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [TrackierCordovaPlugin, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
bootstrap: [AppComponent]
})
export class AppModule {}
Step 3: Verify Initialization
- Build and run your Cordova or Ionic Native project:
- For Cordova:
cordova run androidorcordova run ios - For Ionic:
ionic cap run androidorionic cap run ios
- For Cordova:
- Test on a device or emulator to ensure the SDK initializes without errors.
- Check the console logs for initialization-related messages (if debug logging is enabled).
Expected Outcome
The SDK will initialize when the application starts, registering with Cordova's lifecycle events and enabling tracking capabilities. You can verify initialization by testing tracking features like events or checking the Trackier Panel for data.
Best Practices
- Secure SDK Key: Store the SDK key securely in a configuration file or environment variables, avoiding hardcoding in source code.
- Choose the Correct Environment: Use
TrackierEnvironment.DevelopmentorTrackierEnvironment.Testingfor testing andTrackierEnvironment.Productionfor live apps to prevent mixing test and production data. - Initialize Early: Initialize the SDK as early as possible (e.g., after
devicereadyfor Cordova or inngOnInitfor Ionic) to ensure all events are tracked. - Validate Initialization: Test initialization in a development environment and verify the SDK key is recognized in the Trackier Panel.
- Use Version Control: Commit initialization code to version control to track changes and facilitate collaboration.
- Test Provider Registration: For Ionic Native, ensure the
TrackierCordovaPluginprovider is correctly registered inapp.module.tsto avoid runtime errors.
Troubleshooting
- SDK Key Invalid:
- Verify the SDK key is correctly copied from the Trackier Panel without extra spaces or characters.
- Ensure the key corresponds to the correct application in the Trackier Panel.
- Initialization Fails:
- Check console logs for errors related to
TrackierCordovaPlugin.initializeSDK. - Confirm the SDK package is installed in
node_modules/trackier/cordova_sdk. - For Ionic Native, ensure the
trackierfolder is innode_modules/@awesome-cordova-pluginsandionic cap syncwas executed.
- Check console logs for errors related to
- Provider Not Registered (Ionic Native):
- Verify the
TrackierCordovaPluginis imported and added to theprovidersarray inapp.module.ts. - Check for typos in the import path or provider name.
- Verify the
- Environment Issues:
- Ensure the environment (
Development,Production, orTesting) matches your deployment stage.
- Ensure the environment (
For further assistance, refer to the Trackier Documentation Portal or contact Trackier support at support@trackier.com.