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/core
package 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.js
for Cordova ortab1.page.ts
for Ionic Native). - Import the required Trackier modules and initialize the SDK after the
deviceready
event (Cordova) or in thengOnInit
lifecycle hook (Ionic Native). - Set the environment to one of the following values based on your deployment stage:
TrackierEnvironment.Development
TrackierEnvironment.Production
TrackierEnvironment.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);
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.ts
file in your Ionic project. - Import the
TrackierCordovaPlugin
and add it to theproviders
array.
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 android
orcordova run ios
- For Ionic:
ionic cap run android
orionic 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.Development
orTrackierEnvironment.Testing
for testing andTrackierEnvironment.Production
for live apps to prevent mixing test and production data. - Initialize Early: Initialize the SDK as early as possible (e.g., after
deviceready
for Cordova or inngOnInit
for 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
TrackierCordovaPlugin
provider is correctly registered inapp.module.ts
to 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
trackier
folder is innode_modules/@awesome-cordova-plugins
andionic cap sync
was executed.
- Check console logs for errors related to
- Provider Not Registered (Ionic Native):
- Verify the
TrackierCordovaPlugin
is imported and added to theproviders
array 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.