Skip to content
ruofan edited this page Feb 17, 2025 · 26 revisions

LOGIN

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.

Objective-C
[OmniSegment loginWithUid:@"Your UID"];
swift
OmniSegment.login(uid: "uid")

LOGOUT

When the user logs out:

Objective-C
[OmniSegment logout];
swift
OmniSegment.logout()

SET USER UID

If the user has logged-in and you need to set the uid without login event

Objective-C
[OmniSegment setUidWithUid:@"Your UID"];
swift
OmniSegment.setUid(uid: "uid")

CLEAR USER UID

If you want to reset uid without logout event

Objective-C
[OmniSegment clearUid];
swift
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.

Objective-C
[OmniSegment setWebViewLocation:@"location"];
swift
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.

Objective-C
[OmniSegment resetWebViewLocation];
swift
OmniSegment.resetWebViewLocation()

Set popup redirect callback

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

Objective-C
[OmniSegment setPopupRedirectCallback:^(NSString *url) {
    // Handle redirect URL
    NSLog(@"Redirect to: %@", url);
}];
swift
OmniSegment.setPopupRedirectCallback(_ callback: @escaping (String) -> Void)

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:

Objective-C
[OmniSegment setCurrentPage:@"Your Page Key"];
swift
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 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.

Objective-C
[OmniSegment setFCMToken:@"fake-fcm-token-for-testing"];
swift
import Firebase

let fcmToken = Messaging.messaging().fcmToken
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):

Objective-C
[OmniSegment enableDebugLogs:YES];

[OmniSegment enableDebugLogs:NO];
swift
// 預設 true
OmniSegment.enableDebugLogs()

OmniSegment.enableDebugLogs(true)
OmniSegment.enableDebugLogs(false)

Note

Ensure “Run” Uses Debug Configuration Make sure the Run configuration is set to Debug in Xcode:

  1. Open Xcode.
  2. Go to Product → Scheme → Edit Scheme.
  3. In the Run section, ensure that Build Configuration is set to Debug.
  4. Check that the Debug executable option is enabled.
  5. Confirm that your Build Settings include a DEBUG preprocessor macro.
截圖 2025-02-17 上午10 50 48

Integrate OmniSegment SDK with webview pages

To ensure that events within webview pages are tracked by the SDK, you need to add the OmniSegment content controller to your WKWebViewConfiguration.

Objective-C
[OSGWebViewConfigurationExtension addOmniSegmentContentController:configuration];
swift
func makeUIView(context: Context) -> WKWebView {
    let webViewConfiguration = WKWebViewConfiguration()
    webViewConfiguration.addOmniSegmentContentController()

    let webView = WKWebView(frame: .zero, configuration: webViewConfiguration)
    return webView
}

This integration ensures proper event tracking within webview pages through the SDK.