Unity

Unity

Integration Guide

The OpenBack Unity plugin supports Android & iOS. It is setup to use the Google Unity play service resolver to import the SDKs for both android and iOS. The Google resolver provides a simple way to get the OpenBack SDKs from our maven repository and Cocoapods.

The OpenBack dependencies are listed in OpenBackDependencies.xml. If you need to change versions, feel free to udpate this file.

The plugin and bootstrap source code are available here.

Import OpenBack Unity plugin

To import a package in Unity, use the menu Assets > Import Package > Custom Package....

Option 1: Download OpenBackWithResolver.unitypackage

If you are not already using the Google resolver, everything is provided in this package at the cost of size (~8MB).

Option 2: Download separately OpenBack.unitypackage and Resolver package

If you already have the Google resolver with support for xml dependencies, or want to stay up to date with the latest release, use this option. The OpenBack package is small (~7K).

Option 3: Download only OpenBack.unitypackage

If you do not want to use Google resolver, use the OpenBack package only. You will need to manually download the latest OpenBack SDKs for Android and iOS. Place the aar in the Plugins/Android folder and the unzipped framework in the Plugins/iOS folder. For Android, you will need to add the dependencies manually. For iOS you will need to follow the Integration Guide to make sure the framework is stripped from simulator architectures and added to the embedded binaries.

Android Configuration

Open and edit the provided StreamingAssets/openback.json file with your appCode.
You can also configure the material notification icon in this file for Android 5+. Please refer to the Android documentation for more info.

We recommend using the Gradle build system as manifest merging is done the right way.

Bootstrapping

We provide the package OpenBackBootstrap.unitypackage for single dex applications and OpenBackBootstrap-MultiDex.unitypackage for multi-dex applications to help bootstrap OpenBack on Android. Openback is normally initialized during the onCreate() call of your application class. This extra package is a simple aar that adds a manifest that sets the android:name attribute of your application to use com.openback.unity.UnityApplication. The code is available here.

If your application already uses a custom Application class, call OpenBack like this:

package com.openback.unity;
import android.app.Application;
import android.content.Context;
import android.util.Log;
import com.openback.OpenBack;
public class YourUnityApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Init OpenBack
initOpenBack();
}
private void initOpenBack() {
try {
Context context = getApplicationContext();
OpenBack.start(new OpenBack.Config(context));
} catch (Exception e) {
Log.d("OpenBack", "OpenBack start error", e);
}
}
}

Firebase Setup

Add the OpenBack Firebase service handlers in your Android manifest. See Setting Up Firebase for more details.

When using the resolver, uncomment the Firebase sections in the OpenBack dependencies OpenBack/Editor/OpenBackDependencies.xml then run the resolver again to import the required libraries. You need to copy the goole-services.json file you get from your Firebase console. See Setting Up Firebase for more details.

You also have the option to use the Firebase SDK for Unity directly. Download the Firebase SDK and import FirebaseMessaging.unitypackage in your project. Follow the Setup for Android steps.

Location Services

Starting with version 2.4.0, the location service is not a hard dependency. If you plan on using location triggers, uncomment the section in the OpenBack dependencies OpenBack/Editor/OpenBackDependencies.xml then run the resolver again.

iOS Configuration

Update OpenBack Configuration

Open OpenBack/Editor/OpenBackPostInstall.cs.

UpdateInfoPList() is used to add extra values to the info.plist - this is where you want to add the URL schemes needed by the Other Apps trigger.
CreateOpenBackConfig() is usesd to generate the OpenBackConfig.plist file - this is where you set the AppCode and the features you want to use.

Check the general iOS Configuration Guide for more info on the features and expected values.

Enable Push Notification

Open the XCode workspace and enable psuh notification in the project capabilities. See the Setup APNs Certificates for Push Notifications for more info.

PushNotifications

API Documentation

These endpoints are used for your app to interact directly with OpenBack.

coppaCompliant

public void coppaCompliant(bool compliant)

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.

Example:

OpenBack openBack = OpenBack.SharedInstance;
openBack.coppaCompliant (true);

gdprForgetUser

public bool gdprForgetUser(bool forgetUser)

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:

OpenBack openBack = OpenBack.SharedInstance;
openBack.gdprForgetUser (true);

getSdkVersion

public string getSdkVersion ()

Returns the current OpenBack version. The version is platform specific.

Example:

OpenBack openBack = OpenBack.SharedInstance;
string version = openBack.getSdkVersion ();

logGoal

public bool logGoal(string goal, int step, double value)

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.

Example:

OpenBack openBack = OpenBack.SharedInstance;
openBack.logGoal ("Hello", 1, 12.3);

setCustomTrigger

public bool setCustomTrigger (OpenBackTrigger trigger, string value)
public bool setCustomTrigger (OpenBackTrigger trigger, int value)
public bool setCustomTrigger (OpenBackTrigger trigger, float value)

Set a custom trigger value. Value can be string, int or double.
For the trigger index, use CustomTrigger1 to CustomTrigger10,

Example:

OpenBack openBack = OpenBack.SharedInstance;
openBack.setCustomTrigger (OpenBackTrigger.CustomTrigger1, "Hello");
openBack.setCustomTrigger (OpenBackTrigger.CustomTrigger2, 42);
openBack.setCustomTrigger (OpenBackTrigger.CustomTrigger3, 1.2345);

triggerEvent

Use this API to trigger an event. If a message matches your event and any other triggers, the message will be displayed after the given delay.

Delay is in seconds. If delay is a non-negative number, it will override the default value is set in the OpenBack Dashboard.

Example:

public void triggerEvent (string eventName, long delay)

cancelEvent

Use this API to cancel an event. Removes the displayed and scheduled notifications for the message set to use that event.

Example:

public void cancelEvent(string eventName)

setUserInfo

public bool setUserInfo (OpenBackUserInfo userInfo)

The application can pass some extra user information using the OpenBackUserInfo struct by setting the following fields:

NameTypeDescription
AddressLine1StringAddress line 1
AddressLine2StringAddress line 2
AdvertisingIdStringAdvertising identifier set by the application
AgeStringAge
CityStringCity
CountryStringCountry
CountryCodeStringISO-2 country code
DateOfBirthStringDate of birth YYYY-MM-DD
EmailStringEmail Address
FirstNameStringFirst name
GenderStringGender
OptInUpdatesStringOpting in for message updates "true"/"false"
PhoneNumberStringPhone Number (international format)
PostCodeStringPostal code
ProfessionStringProfession
StateStringState
SurnameStringSurname
TitleStringTitle
Identity1StringCustom user identifier 1
Identity2StringCustom user identifier 2
Identity3StringCustom user identifier 3
Identity4StringCustom user identifier 4
Identity5StringCustom user identifier 5

Example:

OpenBack openBack = OpenBack.SharedInstance;
OpenBackUserInfo userInfo = new OpenBackUserInfo ();
userInfo.Email = "example@openback.com";
userInfo.FirstName = "john";
openBack.setUserInfo (userInfo);