Protocolo NowAnalyticsServiceDelegate - iOS

  • Versão de lançamento: Xanadu
  • Atualizado 1 de ago. de 2024
  • 5 min. de leitura
  • O protocolo NowAnalyticsServiceDelegate fornece funções de retorno de chamada que fornecem informações sobre o início e o término de uma sessão de usuário e 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
    screenName Cadeia de caracteres Nome da tela para detectar se há alguma mudança.
    Tabela 2. Retorna
    Tipo Descrição
    Cadeia de caracteres Nome personalizado a ser usado para substituir o screenName passado.

    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 termina.

    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. Retorna
    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. Retorna
    Tipo Descrição
    Booliano Sinalizador que indica que a sessão está sendo iniciada.
    Valores válidos:
    • verdadeiro: a sessão está começando
    • falso: a sessão não está sendo iniciada

    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. Retorna
    Tipo Descrição
    Booliano Sinalizador que indica que a sessão está terminando.
    Valores válidos:
    • verdadeiro: a sessão está sendo encerrada
    • falso: a sessão não está terminando

    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. Retorna
    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)