SDK Migration - Unity SDK (v4)

This article contains the information required to update the Airbridge Unity SDK. We recommend checking the information regarding all versions.

Update from v1.x to v4.0

Check the information below when updating the Unity SDK to v4.0.

SDK installation and initialization

Attention

When updating the Airbridge Unity SDK from v1.x.x to v4.0.0, remove the previously imported folders listed below before adding the Airbridge Unity SDK v4.0.0 package.

  • Assets/Airbridge

  • Assets/Plugins/Airbridge

The key values of Assets/Airbridge/Resources/AirbridgeData.asset have been changed. Change the key values as follows.

AirbridgeData.asset (v1)

AirbridgeData.asset (v4)

iosUriScheme

iOSURIScheme

The AirbridgeUnity.StartTracking function has been replaced with the Airbridge.StartTracking function.

12
- AirbridgeUnity.StartTracking();
+ Airbridge.StartTracking();

The AirbridgeUnity.StopTracking function has been replaced with the Airbridge.StopTracking function.

12
- AirbridgeUnity.StopTracking();
+ Airbridge.StopTracking();

Deep Linking

The AirbridgeUnity.SetDeeplinkCallback function has been replaced with the Airbridge.SetOnDeeplinkReceived function.

123456789101112131415161718
public class AirbridgeManager : MonoBehaviour
{
    private void Awake()
    {
-        AirbridgeUnity.SetDeeplinkCallback(gameObject.name);

+        Airbridge.SetOnDeeplinkReceived((string url)  =>
+        {
+            // show proper content
+        });
    }

-    // Method will call by Airbridge when deeplink detected
-    private void OnTrackingLinkResponse(string url)
-    {
-        // show proper content
-    }   
}

For Android, the AirbridgeUnity.processDeeplinkData function has been replaced with the AirbridgeUnity.processHandleDeeplink function.

12345678
package co.ab180.airbridge.unity;

@Override
protected void onResume() {
    super.onResume();
-    AirbridgeUnity.processDeeplinkData(getIntent());
+    AirbridgeUnity.processHandleDeeplink(getIntent());
}

In-app event and user data

Attention

Please enter the value into AirbridgeAttribute.VALUE instead of the existing AirbridgeEvent.SetTotalValue.

The logic where totalValue overwrites value if totalValue is used and value is defined has been removed from Unity SDK v4.0.0.

The AirbridgeUnity.TrackEvent function has been replaced with the Airbridge.TrackEvent function.

Replace the AirbridgeUnity.TrackEvent function to Airbridge.TrackEvent function following the example code below.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
- AirbridgeEvent @event = new AirbridgeEvent(Airbridge.Constants.CATEGORY.ORDER_COMPLETED);
- // action
- @event.SetAction("Tool");
- // label
- @event.SetLabel("Hammer");
- // value
- @event.SetValue(10);
-         
- // semantic attribute (provided by sdk)
- @event.SetCurrency("USD");
-         
- List<Airbridge.Ecommerce.Product> products = new List<Airbridge.Ecommerce.Product>();
- Airbridge.Ecommerce.Product plasticHammer = new Airbridge.Ecommerce.Product();
- // semantic attribute value (provided by sdk)
- plasticHammer.SetId("12345");
- // semantic attribute value (not provided by sdk)
- plasticHammer.AddData("name", "PlasticHammer");
- products.Add(plasticHammer);
- @event.SetProducts(products.ToArray());
-     
- // semantic attribute (not provided by sdk)
- @event.AddSemanticAttribute("totalQuantity", 1);
-        
- // custom attribute
- @event.AddCustomAttribute("promotion", "FirstPurchasePromotion");

+ Airbridge.TrackEvent(
+    category: AirbridgeCategory.ORDER_COMPLETED,
+    semanticAttributes: new Dictionary<string, object>()
+    {
+        // action
+        { AirbridgeAttribute.ACTION, "Tool" },
+        // label
+        { AirbridgeAttribute.LABEL, "Hammer" },
+        // value
+        { AirbridgeAttribute.VALUE, 10 },
+        // semantic attribute (provided by sdk)
+        { AirbridgeAttribute.CURRENCY, "USD" },
+        {
+            AirbridgeAttribute.PRODUCTS, new List<Dictionary<string, object>>()
+            {
+                new Dictionary<string, object>()
+                {
+                    // semantic attribute value (provided by sdk)
+                    { AirbridgeAttribute.PRODUCT_ID, "12345" },
+                    // semantic attribute value (not provided by sdk)
+                    { "name", "PlasticHammer" }
+                }
+            }
+        },
+        // semantic attribute (not provided by sdk)
+        { "totalQuantity", 1 }
+    },
+    customAttributes: new Dictionary<string, object>()
+    {
+        // custom attribute
+        { "promotion", "FirstPurchasePromotion" }
+    }
+);

Attention

The AirbridgeEvent class has been removed.

The first parameter of the Airbridge.TrackEvent function must include category information contained in the AirbridgeEvent constructor.

The second parameter of the Airbridge.TrackEvent function must include values from AirbridgeEvent.SetAction, AirbridgeEvent.SetLabel, AirbridgeEvent.SetValue, and Semantic Attributes.

The third parameter of the Airbridge.TrackEvent function must include values from the Custom Attributes.

The AirbridgeUnity.SetUser function has been replaced with the Airbridge.SetUser related functions. The SetUser function is no longer supported.

12345678910111213
- AirbridgeUser user = new AirbridgeUser();
- user.SetId("personID");
- user.SetEmail("persondoe@airbridge.io");
- user.SetPhoneNumber("1(123)123-1234");
- user.SetAttribute("key", "value");
- user.SetAlias("key", "value");
- AirbridgeUnity.SetUser(user);

+ Airbridge.SetUserID("personID");
+ Airbridge.SetUserEmail("persondoe@airbridge.io");
+ Airbridge.SetUserPhone("1(123)123-1234");
+ Airbridge.SetUserAttribute("key", "value");
+ Airbridge.SetUserAlias("key", "value");

Additional settings

The AirbridgeUnity.ImpressionTrackingLink function has been replaced with the Airbridge.Impression function.

12345678910111213
- AirbridgeUnity.ImpressionTrackingLink("https://abr.ge/~~~");

+ Airbridge.Impression(
+    trackingLink: "https://abr.ge/~~~",
+    onSuccess: () =>
+    {
+        // Handle on success
+    },
+    onFailure: (Exception exception) =>
+    {
+        // Handle on failure
+    }
+);

The AirbridgeUnity.ClickTrackingLink function has been replaced with the Airbridge.Click function.

12345678910111213
- AirbridgeUnity.ClickTrackingLink("https://abr.ge/~~~");

+ Airbridge.Click(
+    trackingLink: "https://abr.ge/~~~",
+    onSuccess: () =>
+    {
+        // Handle on success
+    },
+    onFailure: (Exception exception) =>
+    {
+        // Handle on failure
+    }
+);

The AirbridgeUnity.SetOnAttributionReceived function has been replaced with the Airbridge.SetOnAttributionReceived function.

123456789101112131415161718
public class AirbridgeManager : MonoBehaviour
{
    private void Awake()
    {
-        AirbridgeUnity.SetOnAttributionReceived(gameObject.name);

+        Airbridge.SetOnAttributionReceived((Dictionary<string, object> attributionResult) =>
+        {
+            // using attribution
+        });
    }

-    // Method will call by Airbridge when attribution result received
-    private void OnAttributionResultReceived(string data)
-    {
-        // using attribution
-    }
}

Device Alias

12345678
- AirbridgeUnity.SetDeviceAlias("ADD_YOUR_KEY", "AND_YOUR_VALUE");
+ Airbridge.SetDeviceAlias("ADD_YOUR_KEY", "AND_YOUR_VALUE");

- AirbridgeUnity.RemoveDeviceAlias("DELETE_THIS_KEY");
+ Airbridge.RemoveDeviceAlias("DELETE_THIS_KEY");

- AirbridgeUnity.ClearDeviceAlias();
+ Airbridge.ClearDeviceAlias();

Activation status of the Airbridge SDK

12
- bool isSDKEnabled = AirbridgeUnity.IsSDKEnabled();
+ bool isSDKEnabled = Airbridge.IsSDKEnabled();

The AirbridgeUnity.CreateWebInterface function has been replaced with the Airbridge.CreateWebInterfaceScript, Airbridge.HandleWebInterfaceCommand function.

123456789101112131415161718192021222324252627282930313233343536373839404142434445
private WebViewObject webViewObject;
string postMessageScript;

- AirbridgeWebInterface webInterface;

void Start()
{
    string PostMessageGenerator(string arg) =>
        $@"
if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {{
    window.webkit.messageHandlers.unityControl.postMessage({arg});
}} else {{
    var iframe = document.createElement('IFRAME');
    iframe.setAttribute('src', 'unity:' + {arg});
    document.documentElement.appendChild(iframe);
    iframe.parentNode.removeChild(iframe);
    iframe = null;
}}";

-    webInterface = AirbridgeUnity.CreateWebInterface(WebViewController.WebToken, (string command) => PostMessageGenerator(command));
-    postMessageScript = webInterface.Script;
+    postMessageScript = Airbridge.CreateWebInterfaceScript(WebViewController.WebToken, PostMessageGenerator("payload"));

    try
    {
        webViewObject.Init(
            cb: (msg) =>
            {
-                webInterface.Handle(msg);
+                Airbridge.HandleWebInterfaceCommand(msg);
            },
            ...
            ld: (msg) =>
            {
                webViewObject.EvaluateJS(postMessageScript);
            }
            ...
        );
        webViewObject.LoadURL("https://...");
    }
    catch (System.Exception e)
    {
        ...
    }
}

Was this page helpful?

Have any questions or suggestions?