NowAnalyticsServiceDelegate プロトコル:iOS

  • リリースバージョン: Zurich
  • 更新日 2025年07月31日
  • 所要時間:12分
  • NowAnalyticsServiceDelegate プロトコルは、ユーザーセッションの開始と終了、および画面変更の検出に関する情報を提供するコールバック関数を提供します。

    NowAnalyticsServiceDelegate:nowAnalyticsDidDetectScreen(_ sessionId:文字列)

    画面の変更が検出されたときに通知します。画面名はナビゲーションバーから検出されます。それが不可能な場合は、viewController サブクラス名です。

    表 : 1. パラメーター
    名前 タイプ 説明
    画面名 文字列 変更があるかどうかを検出する画面の名前。
    表 : 2. 戻り値
    タイプ 説明
    文字列 渡された screenName を上書きするために使用するカスタム名。

    この例では、 NowAnalyticsServiceDelegate のデリゲートクラスを定義する方法を示します。

    import NowAnalytics
    
    // Initialize the Analytics SDK
    NowAnalytics.configure(for: URL(string: "https://my.instance.service-now.com")!)
    
    // Define a delegate class for NowAnalyticsServiceDelegate
    class NowAnalyticsDelegate: NowAnalytics.NowAnalyticsServiceDelegate {
      func nowAnalyticsSessionShouldStart() -> Bool {
        // Session is about to start, return true to allow session to start
        return true
      }
    
      func nowAnalyticsSessionDidStart(_ sessionId: String) {
        // Session was started
      }
    
      func nowAnalyticsSessionShouldEnd(_ sessionId: String) -> Bool {
        // Session is about to end, return true to allow session to end
        return true
      }
    
      func nowAnalyticsSessionDidEnd(_ sessionId: String) {
        // Session was ended
      }
    
      func nowAnalyticsDidDetectScreen(_ screenName: String) -> String? {
        // Example of skipping specific screen detection
        if (screenName == "LoginViewController") {
          return nil
        }
    
        // Example of appending a prefix for every screen detected
        return "MyApp_" + screenName
      }
    }
    
    // Register delegate
    private var analyticsDelegate = NowAnalyticsDelegate()  // Keep ref of delegate
    NowAnalytics.sharedAnalyticsService.setDelegate(analyticsDelegate)

    NowAnalyticsServiceDelegate:nowAnalyticsSessionDidEnd(_ sessionId:文字列)

    指定されたセッションが終了したときに 通知します。

    これは、指定されたセッションが実際に終了したときに呼び出されるコールバック関数です。

    表 : 3. パラメーター
    名前 タイプ 説明
    sessionId 文字列 確認するセッションの一意の識別子。
    表 : 4. 返される内容
    タイプ 説明
    なし

    この例では、 NowAnalyticsServiceDelegate のデリゲートクラスを定義する方法を示します。

    import NowAnalytics
    
    // Initialize the Analytics SDK
    NowAnalytics.configure(for: URL(string: "https://my.instance.service-now.com")!)
    
    // Define a delegate class for NowAnalyticsServiceDelegate
    class NowAnalyticsDelegate: NowAnalytics.NowAnalyticsServiceDelegate {
      func nowAnalyticsSessionShouldStart() -> Bool {
        // Session is about to start, return true to allow session to start
        return true
      }
    
      func nowAnalyticsSessionDidStart(_ sessionId: String) {
        // Session was started
      }
    
      func nowAnalyticsSessionShouldEnd(_ sessionId: String) -> Bool {
        // Session is about to end, return true to allow session to end
        return true
      }
    
      func nowAnalyticsSessionDidEnd(_ sessionId: String) {
        // Session was ended
      }
    
      func nowAnalyticsDidDetectScreen(_ screenName: String) -> String? {
        // Example of skipping specific screen detection
        if (screenName == "LoginViewController") {
          return nil
        }
    
        // Example of appending a prefix for every screen detected
        return "MyApp_" + screenName
      }
    }
    
    // Register delegate
    private var analyticsDelegate = NowAnalyticsDelegate()  // Keep ref of delegate
    NowAnalytics.sharedAnalyticsService.setDelegate(analyticsDelegate)

    NowAnalyticsServiceDelegate:nowAnalyticsSessionDidStart(_ sessionId:文字列)

    指定されたセッションが開始されたときに通知します。

    これは、指定されたセッションが実際に開始されたときに呼び出されるコールバック関数です。

    表 : 5. パラメーター
    名前 タイプ 説明
    sessionId 文字列 確認するセッションの一意の識別子。
    表 : 6. 返される内容
    タイプ 説明
    ブール セッションが開始されていることを示すフラグ。
    有効な値:
    • true:セッションを開始しています
    • false:セッションは開始されません

    この例では、 NowAnalyticsServiceDelegate のデリゲートクラスを定義する方法を示します。

    import NowAnalytics
    
    // Initialize the Analytics SDK
    NowAnalytics.configure(for: URL(string: "https://my.instance.service-now.com")!)
    
    // Define a delegate class for NowAnalyticsServiceDelegate
    class NowAnalyticsDelegate: NowAnalytics.NowAnalyticsServiceDelegate {
      func nowAnalyticsSessionShouldStart() -> Bool {
        // Session is about to start, return true to allow session to start
        return true
      }
    
      func nowAnalyticsSessionDidStart(_ sessionId: String) {
        // Session was started
      }
    
      func nowAnalyticsSessionShouldEnd(_ sessionId: String) -> Bool {
        // Session is about to end, return true to allow session to end
        return true
      }
    
      func nowAnalyticsSessionDidEnd(_ sessionId: String) {
        // Session was ended
      }
    
      func nowAnalyticsDidDetectScreen(_ screenName: String) -> String? {
        // Example of skipping specific screen detection
        if (screenName == "LoginViewController") {
          return nil
        }
    
        // Example of appending a prefix for every screen detected
        return "MyApp_" + screenName
      }
    }
    
    // Register delegate
    private var analyticsDelegate = NowAnalyticsDelegate()  // Keep ref of delegate
    NowAnalytics.sharedAnalyticsService.setDelegate(analyticsDelegate)

    NowAnalyticsServiceDelegate:nowAnalyticsSessionShouldEnd(_ sessionId:文字列)

    指定されたセッション の終了直前に通知します。

    これは、指定されたセッションが終了しようとしているときに呼び出されるコールバック関数です。

    表 : 7. パラメーター
    名前 タイプ 説明
    sessionId 文字列 確認するセッションの一意の識別子。
    表 : 8. 返される内容
    タイプ 説明
    ブール セッションの終了を示すフラグ。
    有効な値:
    • true:セッションを終了します
    • false:セッションが終了していません

    この例では、 NowAnalyticsServiceDelegate のデリゲートクラスを定義する方法を示します。

    import NowAnalytics
    
    // Initialize the Analytics SDK
    NowAnalytics.configure(for: URL(string: "https://my.instance.service-now.com")!)
    
    // Define a delegate class for NowAnalyticsServiceDelegate
    class NowAnalyticsDelegate: NowAnalytics.NowAnalyticsServiceDelegate {
      func nowAnalyticsSessionShouldStart() -> Bool {
        // Session is about to start, return true to allow session to start
        return true
      }
    
      func nowAnalyticsSessionDidStart(_ sessionId: String) {
        // Session was started
      }
    
      func nowAnalyticsSessionShouldEnd(_ sessionId: String) -> Bool {
        // Session is about to end, return true to allow session to end
        return true
      }
    
      func nowAnalyticsSessionDidEnd(_ sessionId: String) {
        // Session was ended
      }
    
      func nowAnalyticsDidDetectScreen(_ screenName: String) -> String? {
        // Example of skipping specific screen detection
        if (screenName == "LoginViewController") {
          return nil
        }
    
        // Example of appending a prefix for every screen detected
        return "MyApp_" + screenName
      }
    }
    
    // Register delegate
    private var analyticsDelegate = NowAnalyticsDelegate()  // Keep ref of delegate
    NowAnalytics.sharedAnalyticsService.setDelegate(analyticsDelegate)

    NowAnalyticsServiceDelegate:nowAnalyticsSessionShouldStart(_ sessionId:文字列)

    指定されたセッションが開始しようとしているかどうかを通知します。

    これは、指定されたセッションが開始されようとしているときに呼び出されるコールバック関数です。

    表 : 9. パラメーター
    名前 タイプ 説明
    sessionId 文字列 確認するセッションの一意の識別子。
    表 : 10. 返される内容
    タイプ 説明
    なし

    この例では、 NowAnalyticsServiceDelegate のデリゲートクラスを定義する方法を示します。

    import NowAnalytics
    
    // Initialize the Analytics SDK
    NowAnalytics.configure(for: URL(string: "https://my.instance.service-now.com")!)
    
    // Define a delegate class for NowAnalyticsServiceDelegate
    class NowAnalyticsDelegate: NowAnalytics.NowAnalyticsServiceDelegate {
      func nowAnalyticsSessionShouldStart() -> Bool {
        // Session is about to start, return true to allow session to start
        return true
      }
    
      func nowAnalyticsSessionDidStart(_ sessionId: String) {
        // Session was started
      }
    
      func nowAnalyticsSessionShouldEnd(_ sessionId: String) -> Bool {
        // Session is about to end, return true to allow session to end
        return true
      }
    
      func nowAnalyticsSessionDidEnd(_ sessionId: String) {
        // Session was ended
      }
    
      func nowAnalyticsDidDetectScreen(_ screenName: String) -> String? {
        // Example of skipping specific screen detection
        if (screenName == "LoginViewController") {
          return nil
        }
    
        // Example of appending a prefix for every screen detected
        return "MyApp_" + screenName
      }
    }
    
    // Register delegate
    private var analyticsDelegate = NowAnalyticsDelegate()  // Keep ref of delegate
    NowAnalytics.sharedAnalyticsService.setDelegate(analyticsDelegate)