Usage - beBit-tech/bebit-tech-android-app-sdk GitHub Wiki
Set User
After the user logs in, you need to provide the user's uid to the sdk, so that the sdk can use it when sending records.
OmniSegment.login("uid")
When the user logs out:
OmniSegment.logout()
If the user has logged-in and you need to set the uid without login event
OmniSegment.setUid("uid")
If you want to reset uid without logout event
OmniSegment.clearUid()
Set device id (cid)
OmniSegment.setDeviceId(id: "id")
Managing WebView Document Location
To customize the document location reported in WebView events, use the setWebViewLocation method provided by OmniSegment SDK. This allows for overriding the default document location with a specified string.
OmniSegment.setWebViewLocation("location")
After setting a custom document location, you may wish to revert to using the default document location in WebView events. Achieve this by invoking the resetWebViewLocation method.
OmniSegment.resetWebViewLocation()
Setting Up Popup Redirect Callbacks
To set a popup redirect callback, follow:
OmniSegment.setPopupRedirectCallback(redirectCallback)
Set Current Page
To ensure the OmniSegment SDK properly manages pop-up displays, it's essential to update the current page context. Each time a user navigates to a new page within your app, invoke the following method with a predefined page_key:
OmniSegment.setCurrentPage("page_key")
This page_key serves as an identifier for the SDK to make decisions about displaying pop-ups. It should be defined in advance and triggered upon each page entry. The page_key is flexible and can be in either English or Chinese.
[!IMPORTANT] The implementation of this function is crucial for the app's pop-up triggering mechanism. Ensure that setCurrentPage is called every time a user enters a new page to maintain accurate and effective pop-up management.
Set Firebase Cloud Messaging Token
Note: Before using this feature, you need to integrate Firebase SDK into your project and enable GooFirebase services for your app.
You need to provide the user's Firebase Cloud Messaging Token to the sdk, so that the sdk can use it when sending records and push notifications.
OmniSegment.setFCMToken("fcmToken")
After setting the FCM Token with setFCMToken, it's important to trigger an appOpen() event to send this information to the OmniSegment system. This ensures the SDK is fully configured to utilize the FCM Token for push notifications and data recording.
[!IMPORTANT] The appOpen() event is essential for completing the setup. Make sure to call it following the FCM Token configuration to ensure the OmniSegment system receives the necessary information.
Enable debug logs
To enable debug logs, add the following code to your application delegate (or scene delegate):
OmniSegment.enableDebugLogs()
Integrating OmniSegment SDK with WebView Pages in Android
Add the addOmniSegmentJavascriptInterface to the WKWebViewConfiguration. This ensures that events within webview pages are tracked by the SDK.
package com.bebit.xxxx.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.bebittech.omnisegment.OmniSegment;
public class ProfileActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
webView = findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true); // Enable JavaScript
webSettings.setDomStorageEnabled(true); // Enable DOM storage API
webSettings.setLoadWithOverviewMode(true); // Loads the WebView completely zoomed out
webSettings.setUseWideViewPort(true); // Enables wide viewport
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); // Use default cache mode
webView.loadUrl("https://ray-li-store.myshopify.com");
OmniSegment.addOmniSegmentJavascriptInterface(webView);
}
}
[!IMPORTANT] OmniSegment.addOmniSegmentJavascriptInterface method to add the necessary JavaScript interface to your WebView. This interface allows the OmniSegment SDK to track events within the WebView content.