Send App Event with Web SDK (Deprecated)

Send event from web (option 2)

On web, when iOS app, init Airbridge iOS SDK with mobileApp to send Mobile Event.

Example code - Javascript

(function(a_,i_,r_,_b,_r,_i,_d,_g,_e){if(!a_[_b]||!a_[_b].queue){_g=i_.getElementsByTagName(r_)[0];a_[_b]={queue:[]};_d={};for(_i=0;_i<_r.length;_d={$jscomp$loop$prop$m$2:_d.$jscomp$loop$prop$m$2},_i++)_d.$jscomp$loop$prop$m$2=_r[_i],~_d.$jscomp$loop$prop$m$2.indexOf(".")&&(_e=_d.$jscomp$loop$prop$m$2.split(".")[0],a_[_b][_e]=a_[_b][_e]||{},a_[_b][_e][_d.$jscomp$loop$prop$m$2.split(".")[1]]=function(_d){return function(){a_[_b].queue.push([_d.$jscomp$loop$prop$m$2,arguments])}}(_d)),a_[_b][_d.$jscomp$loop$prop$m$2]=function(_d){return function(){a_[_b].queue.push([_d.$jscomp$loop$prop$m$2,arguments])}}(_d);_d=i_.createElement(r_);_d.async=1;_d.src="//static.airbridge.io/sdk/latest/airbridge.min.js";_g.parentNode.insertBefore(_d,_g)}})(window,document,"script","airbridge","init setBanner setDownload setDeeplinks sendSMS sendWeb setUserAgent setUserAlias addUserAlias setMobileAppData setUserId setUserEmail setUserPhone setUserAttributes setDeviceIFV setDeviceIFA setDeviceGAID events.send events.signIn events.signUp events.signOut events.purchased events.addedToCart events.productDetailsViewEvent events.homeViewEvent events.productListViewEvent events.searchResultViewEvent".split(" "));

var deviceUUID = undefined;
var packageName = undefined;
var isLimitAdTracking = undefined;
var appVersion = undefined;
var ifa = undefined;
var ifv = undefined;
var gaid = undefined;
    
try {
    deviceUUID = window.AirbridgeDeviceInfo.getDeviceUUID();
    packageName = window.AirbridgeDeviceInfo.getPackageName();
    isLimitAdTracking = window.AirbridgeDeviceInfo.isLimitAdTracking();
    appVersion = window.AirbridgeDeviceInfo.getAppVersion();
} catch {}

try {
    ifa = window.AirbridgeDeviceInfo.getIFA();
    ifv = window.AirbridgeDeviceInfo.getIFV();
} catch {}

try {
    gaid = window.AirbridgeDeviceInfo.getGAID();
} catch {}
    
if (typeof deviceUUID === 'string'
    && typeof packageName === 'string'
    && typeof isLimitAdTracking === 'boolean'
    && typeof appVersion === 'string'
    && typeof ifa === 'string'
    && typeof ifv === 'string')
{
    // when ios app
    airbridge.init({
        app: 'APP_NAME',
        webToken: 'WEB_TOKEN',
        mobileApp: {
            deviceUUID: deviceUUID,
            packageName: packageName,
            limitAdTracking: isLimitAdTracking,
            appVersion: appVersion,
            ifa: ifa,
            ifv: ifv,
        }
    });
} else if (typeof deviceUUID === 'string' 
    && typeof packageName === 'string'
    && typeof isLimitAdTracking === 'boolean'
    && typeof appVersion === 'string'
    && typeof gaid === 'string') {
    // when android app
    airbridge.init({
        app: 'APP_NAME',
        webToken: 'WEB_TOKEN',
        mobileApp: {
            deviceUUID: deviceUUID,
            packageName: packageName,
            limitAdTracking: isLimitAdTracking,
            appVersion: appVersion,
            gaid: gaid,
        }
    });
} else {
    // when browser
    airbridge.init({
        app: 'APP_NAME',
        webToken: 'WEB_TOKEN'
    });
}
// when ios app, send web event
// when browser, send mobile event
airbridge.events.send('category', {
    'label': 'label',
    'action': 'action',
    'value': 123.0,
    'customAttributes': {
        'custom1': 123,
        'custom2': 'abc'
    }
});

Example code - ViewController

#import "ViewController.h"

#import <WebKit/WebKit.h>
#import <AirBridge/AirBridge.h>
#import <AdSupport/AdSupport.h>

@interface ViewController ()

@end

@implementation ViewController {
    WKWebView* webView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString* insertDeviceInfoSource
    = [NSString stringWithFormat:
       @"window.AirbridgeDeviceInfo = {};"
       @"window.AirbridgeDeviceInfo.getDeviceUUID = function () {"
       @"    return \'%@\';"
       @"};"
       @"window.AirbridgeDeviceInfo.getPackageName = function () {"
       @"    return \'%@\';"
       @"};"
       @"window.AirbridgeDeviceInfo.isLimitAdTracking = function () {"
       @"    return %@;"
       @"};"
       @"window.AirbridgeDeviceInfo.getAppVersion = function () {"
       @"    return \'%@\';"
       @"};"
       @"window.AirbridgeDeviceInfo.getIFA = function () {"
       @"    return \'%@\';"
       @"};"
       @"window.AirbridgeDeviceInfo.getIFV = function () {"
       @"    return \'%@\';"
       @"};",
       AirBridge.deviceUUID,
       NSBundle.mainBundle.bundleIdentifier,
       AirBridge.isLimitADTracking ? @"true" : @"false",
       NSBundle.mainBundle.infoDictionary[@"CFBundleShortVersionString"],
       ASIdentifierManager.sharedManager.advertisingIdentifier,
       UIDevice.currentDevice.identifierForVendor];
    WKUserScript* insertDeviceInfoScript
    = [[WKUserScript alloc] initWithSource:insertDeviceInfoSource
                             injectionTime:WKUserScriptInjectionTimeAtDocumentStart
                          forMainFrameOnly:NO];
    
    WKUserContentController* controller = [[WKUserContentController alloc] init];
    [controller addUserScript:insertDeviceInfoScript];
    
    WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
    configuration.userContentController = controller;
    
    webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
    
    self.view = webView;
    
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://..."]]];
}

@end
import UIKit
import WebKit
import AirBridge
import AdSupport

class ViewController: UIViewController {

    var webView: WKWebView? = nil
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let insertDeviceInfoSource
            = String(format:"""
                            window.AirbridgeDeviceInfo = {};
                            window.AirbridgeDeviceInfo.getDeviceUUID = function () {
                                return \'%@\';
                            };
                            window.AirbridgeDeviceInfo.getPackageName = function () {
                                return \'%@\';
                            };
                            window.AirbridgeDeviceInfo.isLimitAdTracking = function () {
                                return %@;
                            };
                            window.AirbridgeDeviceInfo.getAppVersion = function () {
                                return \'%@\';
                            };
                            window.AirbridgeDeviceInfo.getIFA = function () {
                                return \'%@\';
                            };
                            window.AirbridgeDeviceInfo.getIFV = function () {
                                return \'%@\';
                            };
                            """,
                     AirBridge.deviceUUID(),
                     Bundle.main.bundleIdentifier ?? "(null)",
                     AirBridge.isLimitADTracking() ? "true" : "false",
                     Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "(null)"),
                     ASIdentifierManager.shared().advertisingIdentifier,
                     UIDevice.current.identifierForVendor)
        let insertDeviceInfoScript
            = WKUserScript(source: insertDeviceInfoSource,
                           injectionTime: WKUserScriptInjectionTime.atDocumentStart,
                           forMainFrameOnly: false)
        
        let controller = WKUserContentController()
        controller.addUserScript(insertDeviceInfoScript)
        
        let configuration = WKWebViewConfiguration()
        configuration.userContentController = controller
        
        webView = WKWebView(frame: self.view.frame, configuration: configuration)
        
        self.view = webView
        
        if let url = URL(string: "https://...") {
            webView?.load(URLRequest(url: url))
        }
    }
}