Skip to content
ruofan edited this page Apr 1, 2024 · 9 revisions

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()

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()

Set popup redirect callback

To use your own callback function to handle the redirect url behavior on popup button

OmniSegment.setPopupRedirectCallback((url) => callbackFunc())

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:

import OmniSegment from "@bebit-tech/omnisegment";

const HomeScreen = ({navigation}: any) => {
  useEffect(() => {
    OmniSegment.setCurrentPage("Home");
  }, [])
  return (
    <></>
  )
}

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 Google Firebase 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("FCM Token")

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.

Integrate OmniSegment SDK with webview pages

Add the handleWebViewMessage to the WebView onMessage Method. This ensures that events within webview pages are tracked by the SDK.

import { WebView } from 'react-native-webview';
import OmniSegment from "@bebit-tech/omnisegment";
const WebviewScreen = () => {
  
  return (
    <View>
      <WebView 
        source={{ uri: 'https://bebittech' }} 
        onMessage={(event) => {
          try{
            OmniSegment.setWebViewLocation("app://webview")
            OmniSegment.handleWebViewMessage(event.nativeEvent.data)
          }catch(error){
            console.log('Message not handled by SDK');
          }
        }}
      />
    </View>
  );
};

This step is essential for apps with webview pages, allowing for unified event tracking within the SDK.

Clone this wiki locally