H5 pages integrated with the Sensory Web JS SDK, after being embedded in the App, events in the H5 can be sent through the App, and before sending the events, the App-collected preset properties will be added. This feature is turned off by default. If you need to enable it, you need to configure it on both the App and H5 sides.

1. Android Opening Method

Version Requirements

Before SDK initialization, call the SAConfigOptions object's enableJavaScriptBridge() method.

SAConfigOptions saConfigOptions = new SAConfigOptions(SA_SERVER_URL); ··· // 开启 App 打通 H5 // isSupportJellyBean:是否支持 API level 16 及以下的版本,16 及以下版本 API 中,addJavascriptInterface 有安全漏洞,需要谨慎使用。 saConfigOptions.enableJavaScriptBridge(true); // 其他配置 ··· SensorsDataAPI.startWithConfigOptions(this, saConfigOptions);
JAVA

isSupportJellyBean: whether to support versions API level 16 and below. In the API versions below 16, addJavascriptInterface has security vulnerabilities and should be used with caution.

2. iOS Opening Method

Version Requirements

iOS SDK v2.0.8 and above

Before SDK initialization, set the enableJavaScriptBridge property of the SAConfigOptions instance to YES.

SAConfigOptions *options = [[SAConfigOptions alloc] initWithServerURL:SA_SERVER_URL launchOptions:launchOptions]; // 开启 App 打通 H5 options.enableJavaScriptBridge = YES; // 其他配置 [SensorsAnalyticsSDK startWithConfigOptions:option];
OBJECTIVE-C

3. H5 Opening Method

Version Requirements

Web JS SDK v1.15.10 and above

In the SDK initialization code, add the app_js_bridge:true option.

... sensors.init({ 	server_url:'数据接收地址', 	app_js_bridge:true,    ... // 其他配置 }); ...
JS

By default, the App and H5 can only be successfully integrated if the data receiving address of the App is the same as the H5. Users can also configure white_list to enable the integration with a list of App data receiving addresses. H5 will be integrated with all addresses in the list.

... sensors.init({ 	server_url:'数据接收地址', 	app_js_bridge: { 		white_list: ['server_url1','server_url2',....] 	}  ... // 其他配置   }); ...
JS

4. Verify Integration Success

After the App and H5 are integrated, the App SDK will process the data collected by the Web JS SDK. Some identical fields will be overwritten (except $lib), and the following fields will be added:

$app_version	// 应用版本 $app_id	// 应用程序标识 application id $app_name	// 应用名称 $device_id		// 设备 ID $wifi	// 是否 WIFI 网络 $network_type		// 网络类型 $carrier //运营商名称

If there is an H5 event containing $wifi,$network_type$app_version$carrierfields,indicate that the integration between App and H5 is successful.