Skip to content

Cordova

cordova

OpenBack Cordova Plugin

In your project root folder, add the OpenBack plugin with:

cordova plugin add cordova-plugin-openback

The plugin sources and sample code are available on Github here.

Configure OpenBack

Edit your application config.xml with the following preferences:

Set your application code for each platform:

<preference name="com.openback.appCode" value="YOUR_APPLICATION_CODE" />

iOS Specific Configurations

All the values are optional except for the application code.

<platform name="ios">
    <preference name="com.openback.appCode" value="YOUR_IOS_APPLICATION_CODE" />
    <preference name="com.openback.enableAlertNotifications" value="true|false" />
    <preference name="com.openback.enableRemoteNotifications" value="true|false" />
    <preference name="com.openback.enableProximity" value="true|false" />
    <preference name="com.openback.enableMicrophone" value="true|false" />
    <preference name="com.openback.enableMotionCoprocessor" value="true|false" />
    <preference name="com.openback.enableLocation" value="true|false" />
    <preference name="com.openback.requestLocationAlwaysAuthorization" value="true|false" />
    <preference name="com.openback.requestAlertNotificationsAuthorization" value="true|false" />
    <preference name="com.openback.requestMotionCoprocessorAuthorization" value="true|false" />
    <preference name="com.openback.requestMicrophoneAuthorization" value="true|false" />
    <preference name="com.openback.minimumFetchInterval" value="0" />
    <preference name="com.openback.notificationSound" value="YOUR_SOUND_FILE_NAME" />
    <preference name="com.openback.logLevel" value="0" />
</platform>

Preference Description
appCode The application code (Required)
enableAlertNotifications Enable alert notifications (Optional - Default: true)
enableRemoteNotifications Enable remote notifications (Optional - Default: true)
enableProximity Enable proximity sensor (Optional - Default: false)
enableMicrophone Enable microphone (Optional - Default: false)
enableMotionCoprocessor Enable motion coprocessor (Optional - Default: false)
enableLocation Enable location (Optional - Default: false)
requestLocationAlwaysAuthorization Allows OpenBack to prompt for location always authorization (Optional - Default: true)
requestAlertNotificationsAuthorization Allows OpenBack to prompt for system alert notifications authorization (Optional - Default: true)
requestMotionCoprocessorAuthorization Allows OpenBack to prompt for motion coprocessor access authorization (Optional - Default: true)
requestMicrophoneAuthorization Allows OpenBack to prompt for microphone authorization (Optional - Default: true)
minimumFetchInterval Set the minimim fetch interval in seconds (Optional - Default: 0). Use -1 for UIApplicationBackgroundFetchIntervalNever. Use 0 for UIApplicationBackgroundFetchIntervalMinimum
notificationSound Set the notification sound (Optional - Default: UILocalNotificationDefaultSoundName)
logLevel The debug log level (Opetional - Default: 0 - Up to 5 for verbose)

APNS for Push Notifications

Follow the information from the iOS Integration Guide.

Android Specific Configurations

OpenBack for android requires a minimum SDK of 16.

<platform name="android">
    <preference name="android-minSdkVersion" value="16" />
    <preference name="com.openback.appCode" value="msddgcjucx" />
    <resource-file src="openback.json" target="assets/openback.json" />
</platform>

Edit openback.json

This file is used by the OpenBack SDK to set the notification icon for android 5+. Make sure the icon is copied to your android platform. You can customize the light, vibration pattern and sound too. For more info, check Android Integration guide.

The appCode should also be set in this file. It is used by the SDK to setup itself during an application upgrade.

When building for android, make sure the openback.json file is in the assets folder. If not, you might need to try with:

<resource-file src="openback.json" target="app/src/main/assets/openback.json" />

Firebase

Firebase is also required for some features (instant message update, regular push messages). We recommend using https://www.npmjs.com/package/cordova-plugin-firebase.

Android Manifest

Refer to the Android Integration guide to setup the manifest depending on the triggers the application will use. Include the extra permissions and receiver actions in the config.xml file of your application.

API

OpenBack SDK API is accessible in javascript via the window.openback interface.

The success and failure parameters are callback functions.

coppaCompliant

If your application needs COPPA to be enabled, set the COPPA compliant status with this function. If COPPA is enabled, messages will not run unless compliant is set to true.

coppaCompliant(compliant, success, failure)
window.openback.coppaCompliant(true);

gdprForgetUser

When your user requests that all the data should be erased, set this value to true. It will inform the OpenBack server to remove all logs for the current user. All future logs will be erased after processing. If you wish to be fully GDPR complient, you also need to enable GDPR in your application settings on the OpenBack Dashboard.

Example:

gdprForgetUser(forgetUser, success, failure)
window.openback.gdprForgetUser(true);

Logging a Goal

At any point, you can log a goal that is associated with a message. Make sure to use the Goal code, not the Goal name.

logGoal(goal, step, value, success, failure)
window.openback.logGoal("Test", 1, 12.3);

User Info & Custom Values

setCustomTrigger

Set a custom trigger value. Value can be string, integer or double.
For the trigger index, use CUSTOM_TRIGGER_1 to CUSTOM_TRIGGER_10.

setCustomTrigger(int trigger, id value, success, failure)
window.openback.setCustomTrigger(window.openback.CUSTOM_TRIGGER_1, "customString");
window.openback.setCustomTrigger(window.openback.CUSTOM_TRIGGER_2, 123);
window.openback.setCustomTrigger(window.openback.CUSTOM_TRIGGER_3, 2.56);

setUserInfo

The application can pass some extra user information using a simple dictionary object by setting the following fields:

Name Type Description
addressLine1 string Address line 1
addressLine2 string Address line 2
advertisingId string Advertising identifier set by the application
age string Age
city string City
country string Country
countryCode string ISO-2 country code
dateOfBirth string Date of birth YYYY-MM-DD
emailAddress string Email Address
firstName string First name
gender string Gender
optInUpdates string Opting in for message updates "true"/"false"
phoneNumber string Phone Number (international format)
postCode string Postal code
profession string Profession
state string State
surname string Surname
title string Title
identity1 string Custom user identifier 1
identity2 string Custom user identifier 2
identity3 string Custom user identifier 3
identity4 string Custom user identifier 4
identity5 string Custom user identifier 5

Note on Custom User Identifiers:
Identity is for use with the OpenBack API. If you are not an OpenBack API client, don't use them. Identities are bound to the current OpenBack user, so changing any one of them will reset user and campaign usage. A usage example: when your application has users that can login and logout, you can set one of the Identity to a token used in your system to identify that user. Later on, using the OpenBack API, you can fetch details from that user.

setUserInfo(object, success, failure)
window.openback.setUserInfo({
    'firstName': 'John',
    'surname': 'Doe',
    'emailAddress': 'john@doe.com'
});

sdkVersion

Returns the current OpenBack SDK version.

string sdkVersion(success, failure)
window.openback.version(function(v) {
    console.log("Version: " + v);
});