NowAnalyticsServiceDelegate protocol - iOS

  • 릴리스 버전: Australia
  • 업데이트 날짜 2026년 03월 12일
  • 소요 시간: 14분
  • The NowAnalyticsServiceDelegate protocol provides callback functions that provide information about the starting and ending of a user session and screen change detection.

    NowAnalyticsServiceDelegate - nowAnalyticsDidDetectScreen( _ sessionId: String)

    Notifies when a screen change is detected. The screen name is detected from the navigation bar. If that is not possible, it is the viewController subclass name.

    표 1. Parameters
    Name Type Description
    screenName String Name of the screen to detect whether there is any change.
    표 2. Returns
    Type Description
    String Custom name to use to override the passed screenName.

    This example shows how to define a delegate class for 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: String)

    Notifies when the specified session has ended.

    This is a callback function that gets called when the specified session actually ends.

    표 3. Parameters
    Name Type Description
    sessionId String Unique identifier of the session to check.
    표 4. Returns
    Type Description
    None

    This example shows how to define a delegate class for 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: String)

    Notifies when the specified session has started.

    This is a callback function that gets called when the specified session actually starts.

    표 5. Parameters
    Name Type Description
    sessionId String Unique identifier of the session to check.
    표 6. Returns
    Type Description
    Boolean Flag that indicates that the session is starting.
    Valid values:
    • true: Session is starting
    • false: Session is not starting

    This example shows how to define a delegate class for 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: String)

    Notifies when the specified session is about to end.

    This is a callback function that gets called when the specified session is about to end.

    표 7. Parameters
    Name Type Description
    sessionId String Unique identifier of the session to check.
    표 8. Returns
    Type Description
    Boolean Flag that indicates that the session is ending.
    Valid values:
    • true: Session is ending
    • false: Session is not ending

    This example shows how to define a delegate class for 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: String)

    Notifies whether the specified session is about to start.

    This is a callback function that gets called when the specified session is about to start.

    표 9. Parameters
    Name Type Description
    sessionId String Unique identifier of the session to check.
    표 10. Returns
    Type Description
    None

    This example shows how to define a delegate class for 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)