Skip to content

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 libraries for both android and iOS. The Google resolver provides a simple way to get the OpenBack libraries 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 libraries 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 a package OpenBackBootstrap.unitypackage 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 or GCM service handlers in your Android manifest. See Setting Up Firebase for more details.

When using the resolver, uncomment the Firebase or GCM 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 APN 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, campaigns 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 campaign. 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);

setUserInfo

public bool setUserInfo (OpenBackUserInfo userInfo)

The application can pass some extra user information using the OpenBackUserInfo struct 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
Email String Email Address
FirstName String First name
Gender String Gender
OptInUpdates String Opting in for campaign 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

Example:

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