Protocolo NowAnalyticsServiceDelegate - iOS

  • Versão de lançamento: Zurich
  • Atualizado 31 de jul. de 2025
  • 5 min. de leitura
  • . NowAnalyticsServiceDelegate o protocolo fornece funções de retorno de chamada que fornecem informações sobre o início e o término de uma sessão do usuário e a detecção de mudança de tela.

    NowAnalyticsServiceDelegate - nowAnalyticsDidDetectScreen( _ SessionID: Cadeia de caracteres)

    Notifica quando uma mudança de tela é detectada. O nome da tela é detectado na barra de navegação. Se isso não for possível, será o nome da subclasse ViewController.

    Tabela 1. Parâmetros
    Nome Tipo Descrição
    Nome de tela Cadeia de caracteres Nome da tela para detectar se há alguma mudança.
    Tabela 2. Retornos
    Tipo Descrição
    Cadeia de caracteres Nome personalizado a ser usado para substituir o nome de tela aprovado.

    Este exemplo mostra como definir uma classe de delegado para 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: Cadeia de caracteres)

    Notifica quando a sessão especificada foi encerrada.

    Esta é uma função de retorno de chamada que é chamada quando a sessão especificada realmente termina.

    Tabela 3. Parâmetros
    Nome Tipo Descrição
    sessionId Cadeia de caracteres Identificador exclusivo da sessão a ser verificada.
    Tabela 4. Retornos
    Tipo Descrição
    Nenhum(a)

    Este exemplo mostra como definir uma classe de delegado para 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: Cadeia de caracteres)

    Notifica quando a sessão especificada é iniciada.

    Esta é uma função de retorno de chamada que é chamada quando a sessão especificada realmente é iniciada.

    Tabela 5. Parâmetros
    Nome Tipo Descrição
    sessionId Cadeia de caracteres Identificador exclusivo da sessão a ser verificada.
    Tabela 6. Retornos
    Tipo Descrição
    Booliano Sinalizador que indica que a sessão está sendo iniciada.
    Valores válidos:
    • Verdadeiro: A sessão está sendo iniciada
    • Falso: A sessão não está iniciando

    Este exemplo mostra como definir uma classe de delegado para 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: Cadeia de caracteres)

    Notifica quando a sessão especificada está prestes a terminar

    Esta é uma função de retorno de chamada que é chamada quando a sessão especificada está prestes a terminar

    Tabela 7. Parâmetros
    Nome Tipo Descrição
    sessionId Cadeia de caracteres Identificador exclusivo da sessão a ser verificada.
    Tabela 8. Retornos
    Tipo Descrição
    Booliano Sinalizador que indica que a sessão está sendo encerrada .
    Valores válidos:
    • Verdadeiro: A sessão está sendo encerrada
    • Falso: A sessão não está finalizando

    Este exemplo mostra como definir uma classe de delegado para 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: Cadeia de caracteres)

    Notifica se a sessão especificada está prestes a iniciar.

    Esta é uma função de retorno de chamada que é chamada quando a sessão especificada está prestes a iniciar.

    Tabela 9. Parâmetros
    Nome Tipo Descrição
    sessionId Cadeia de caracteres Identificador exclusivo da sessão a ser verificada.
    Tabela 10. Retornos
    Tipo Descrição
    Nenhum(a)

    Este exemplo mostra como definir uma classe de delegado para 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)