This guide covers a hypothetical scenario where you have a hybrid app running on Android and iOS. It explains how to bridge the gap between HTML views and native views so that you can log events in your HTML views and send them to your app.
To apply this method, SDK installation and integration must be done first.
JavaScript interface
Both Android and iOS have native JavaScript interfaces that allow you to call native code from web views.
Android:
iOS:
Implementation consists of the following steps:
HTML code for Webview or webpage
Native code implementation for Webview
Android
HTML code for Android
Add the following HTML code to your Webview or web page.
<h1>Logging Event From Web View</h1>
<div id="main">
<button id="logSignUpEvent" onclick="logSignUPEvent()"> SignUp </button>
</div>
<script type="text/javascript">
function logLoginEvent(){
var eventName = "df_sign_up"
var eventProperty = {'df_sign_channel': 'Facebook'};
window.customJsBridge.logEvent(eventName, JSON.stringify(eventProperty));
}
</script>
WebActivity class
Create a web activity class using the following code.
WhIn a hybrid app written in Swift When calling logEvent
not the logEvent(_ name: String, properties: [String: Any]) method
Please call the logEvent(name: String, properties: [String: Any]) method
Learn more
Enter date and time format properties
Date and time formats yyyy-MM-dd'T'HH:mm:ss.SSS'Z'must be entered as strings in the format.
let today = new Date().toISOString();
let eventName = "df_sign_up"
let eventProperty = {
'custom_property': today
};
window.customJsBridge.logEvent(eventName, JSON.stringify(eventProperty));
let today = new Date().toISOString();
var eventName = "df_sign_up"
let eventProperty = {
'custom_property': today
};
var message = {
'eventName' : eventName,
'eventProperty' : eventProperty
};
webkit.messageHandlers.customJsBridge.postMessage(message);
public class MainJsInterface {
@JavascriptInterface
public void setIdentity(String key, String value){
DFIdentity identity = DFIdentity.get(key);
DfineryProperties.setIdentity(identity, value);
}
}
class MainJsInterface {
@JavascriptInterface
fun setIdentity(key: String?, value: String?) {
val identity: DFIdentity = DFIdentity.get(key)
DfineryProperties.setIdentity(identity, value)
}
}
Please refer to this for information on how to use the Date object in JavaScript .
DFINERY Android SDK accepts user identification information as an Enum. To enter user identification information in HTML, it is recommended to input the value of , convert the string to an Enum in the JavaScript interface, and then call it.