Prerequisites
Complete these prerequisite steps before installing the Singular Cordova SDK to ensure a smooth integration process.
Required Prerequisites:
- Complete planning steps: Follow the guide in Integrating a Singular SDK: Planning and Prerequisites. These steps are mandatory for any Singular SDK integration.
- Functional Cordova app: Ensure you have a working Cordova project with the necessary build tools configured for iOS and/or Android.
- SDK credentials: Retrieve your Singular SDK Key and SDK Secret from the Singular platform at Developer Tools > SDK Integration > SDK Keys.
Critical: Do NOT use the Singular Reporting API Key. Only use the SDK-specific credentials from the SDK Integration page. Using wrong credentials prevents data from reaching Singular.
Installation
Installing the Singular Plugin
Add the Singular plugin to your Cordova project using the Cordova CLI. The plugin provides JavaScript bindings to the native Singular SDKs for iOS and Android.
Install via Cordova CLI
- Open terminal: Navigate to your Cordova project's root directory.
-
Add plugin: Run the following command to install
the Singular SDK plugin:
cordova plugin add singular_cordova_sdk -
Verify installation: Confirm the plugin was added
by checking your
config.xmlfile for the plugin entry or by running:cordova plugin list
Ionic Framework Integration
If you're building your Cordova app with Ionic Framework, follow these additional steps to properly integrate the Singular SDK.
Install Plugin for Ionic
-
Install via Ionic CLI: Use the Ionic Cordova command
to add the plugin:
ionic cordova plugin add singular_cordova_sdk -
Declare Cordova variable: In your main TypeScript
file (typically
app.component.tsorhome.page.ts), declare the Cordova variable at the top:declare var cordova; -
Initialize within platform ready: Use the platform
ready event to ensure native plugins are loaded before SDK initialization:
import { Component } from '@angular/core'; import { Platform } from '@ionic/angular'; declare var cordova; export class HomePage { constructor(public platform: Platform) { this.platform.ready().then(() => { // Initialize Singular SDK here (see SDK Integration section) }); } }
Why Platform Ready? The platform.ready()
promise ensures that Cordova plugins are fully loaded before your
code attempts to access them. Always initialize the Singular SDK
within this callback when using Ionic.
Platform Configuration
Android Configuration
Configure Android-specific permissions and settings to enable core SDK functionality and attribution tracking.
Add Required Permissions
Add the necessary Android permissions to your Cordova
config.xml file to enable attribution, network access, and
install referrer tracking.
-
Open config.xml: Navigate to the root of your Cordova
project and open the
config.xmlfile. -
Add permissions: Within the
<platform name="android">section, add the following permission:<platform name="android"> <!-- Required for GAID collection and attribution --> <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest"> <uses-permission android:name="com.google.android.gms.permission.AD_ID" /> </edit-config> </platform>
Important for Kids Apps: If you're integrating the
Kids SDK,
do NOT add the com.google.android.gms.permission.AD_ID
permission. This permission is required for standard apps but must
be omitted for apps targeting children under 13 to comply with COPPA
regulations.
Additional Permissions (Auto-Added)
The following permissions are automatically added by the Singular Cordova plugin and do not require manual configuration:
-
android.permission.INTERNET- Network access for data transmission -
android.permission.ACCESS_NETWORK_STATE- Network state monitoring -
BIND_GET_INSTALL_REFERRER_SERVICE- Install referrer tracking
iOS Configuration
iOS configuration is handled automatically by the Cordova plugin. No additional manual configuration steps are required for iOS projects.
CocoaPods Installation: When building for iOS, Cordova
automatically runs pod install to fetch required dependencies.
Ensure you have CocoaPods installed on your development machine.
SDK Integration
Privacy Compliance: Comply with privacy laws in your operating regions, including GDPR, CCPA, COPPA, and others when implementing the Singular SDK. For guidance, see SDK Opt-In and Opt-Out Practices.
Initialize the Singular SDK every time your app launches. SDK initialization is essential for all Singular attribution functionality and creates a new session for calculating user retention metrics.
Basic SDK Initialization
Create a SingularConfig object with your SDK credentials
and initialize the SDK using the init() method. This should
be done as early as possible in your app's lifecycle.
Initialization Example
- Get credentials: Log into your Singular account and navigate to Developer Tools > SDK Integration > SDK Keys to find your SDK Key and Secret.
-
Create configuration: Instantiate a
SingularConfigobject with your credentials. -
Initialize SDK: Call
init()to start the SDK.
// Create the Singular configuration object
var singularConfig = new cordova.plugins.SingularCordovaSdk.SingularConfig(
"YOUR_SDK_KEY",
"YOUR_SDK_SECRET"
);
// Initialize the Singular SDK
cordova.plugins.SingularCordovaSdk.init(singularConfig);
Advanced Configuration
Configure additional SDK features by chaining configuration methods before
calling init(). This example demonstrates common configuration
options including deep linking, logging, and session timeout.
// Create configuration with credentials
var singularConfig = new cordova.plugins.SingularCordovaSdk.SingularConfig(
"YOUR_SDK_KEY",
"YOUR_SDK_SECRET"
);
// Enable debug logging (disable in production)
singularConfig.withLoggingEnabled();
// Set custom session timeout (default is 60 seconds)
singularConfig.withSessionTimeoutInSec(120);
// Configure deep linking handler
var linkHandler = function(data) {
var deeplink = data.deeplink;
var passthrough = data.passthrough;
var isDeferred = data.isDeferred;
console.log("Received deep link:", deeplink);
console.log("Is deferred:", isDeferred);
// Handle navigation based on deep link
if (deeplink) {
// Navigate to appropriate screen
}
};
singularConfig.withSingularLink(linkHandler);
// Set custom user ID (if user is logged in)
singularConfig.withCustomUserId("user_12345");
// Initialize Singular
cordova.plugins.SingularCordovaSdk.init(singularConfig);
Configuration Reference: For a complete list of available configuration options, see the Cordova SDK Configuration Reference.
Meta Install Referrer Attribution
Configure Meta (Facebook) Install Referrer attribution to track installs from Facebook and Instagram ad campaigns.
As of June 18th, 2025: Meta's Advanced Mobile Measurement Reporting (AMM) removes the need for implementing Meta Install Referrer for most use cases. It is not recommended to implement Meta Install Referrer if AMM reporting is enabled for your app.
Enable Meta Install Referrer
If AMM is not enabled or you need Meta Install Referrer for legacy tracking, add your Facebook App ID to the SDK configuration.
- Find Facebook App ID: Log into your Facebook Developer account and navigate to your app's dashboard to locate the App ID.
-
Add to configuration: Use the
withFacebookAppId()method to enable Meta Install Referrer:// Create configuration var singularConfig = new cordova.plugins.SingularCordovaSdk.SingularConfig( "YOUR_SDK_KEY", "YOUR_SDK_SECRET" ); // Enable Meta Install Referrer singularConfig.withFacebookAppId("YOUR_FACEBOOK_APP_ID"); // Initialize SDK cordova.plugins.SingularCordovaSdk.init(singularConfig);
Finding Your Facebook App ID: For detailed instructions on locating your Facebook App ID, see Where can I find an app's Facebook App ID?