---
sourceDocument: Referência de API do Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/pt-BR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - pt-BR

ft:publication_title :

    - Referência de API do Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Protocolo NowAnalyticsServiceDelegate - iOS

# Protocolo NowAnalyticsServiceDelegate - iOS {#ariaid-title1}

* Versão de lançamento: Xanadu
* 
* Atualizado 1 de ago. de 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 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) {#ariaid-title2}

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.
{#NAnServDel-nowAnalDidDetectScreen_S__table_ljr_3bb_kqb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| screenName | Cadeia de caracteres | Nome da tela para detectar se há alguma mudança. |
[Tabela 1. Parâmetros]

{#NAnServDel-nowAnalDidDetectScreen_S__table_ljr_3bb_kqb} {#NAnServDel-nowAnalDidDetectScreen_S__table_mjr_3bb_kqb__entry__2}

| Tipo | Descrição |
|-|-|
| Cadeia de caracteres | Nome personalizado a ser usado para substituir o screenName passado. |
[Tabela 2. Retorna]

{#NAnServDel-nowAnalDidDetectScreen_S__table_mjr_3bb_kqb}  
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) {#ariaid-title3}

Notifica quando a sessão especificada termina.
Esta é uma função de retorno de chamada que é chamada quando a sessão especificada realmente termina.
{#NAnServDel-nowAnalSessionDidEnd_S__table_hnt_b2v_1qb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| sessionId | Cadeia de caracteres | Identificador exclusivo da sessão a ser verificada. |
[Tabela 3. Parâmetros]

{#NAnServDel-nowAnalSessionDidEnd_S__table_hnt_b2v_1qb} {#NAnServDel-nowAnalSessionDidEnd_S__table_int_b2v_1qb__entry__2}

| Tipo | Descrição |
|-|-|
| Nenhum(a) |   |
[Tabela 4. Retorna]

{#NAnServDel-nowAnalSessionDidEnd_S__table_int_b2v_1qb}  
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) {#ariaid-title4}

Notifica quando a sessão especificada é iniciada.
Esta é uma função de retorno de chamada que é chamada quando a sessão especificada é realmente iniciada.
{#NAnServDel-nowAnalSessionDidStart_S__table_ntx_m2v_1qb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| sessionId | Cadeia de caracteres | Identificador exclusivo da sessão a ser verificada. |
[Tabela 5. Parâmetros]

{#NAnServDel-nowAnalSessionDidStart_S__table_ntx_m2v_1qb} {#NAnServDel-nowAnalSessionDidStart_S__table_otx_m2v_1qb__entry__2}

| 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 |
[Tabela 6. Retorna]

{#NAnServDel-nowAnalSessionDidStart_S__table_otx_m2v_1qb}  
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) {#ariaid-title5}

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.
{#NAnServDel-nowAnalSessShouldEnd_S__table_lrd_pcv_1qb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| sessionId | Cadeia de caracteres | Identificador exclusivo da sessão a ser verificada. |
[Tabela 7. Parâmetros]

{#NAnServDel-nowAnalSessShouldEnd_S__table_lrd_pcv_1qb} {#NAnServDel-nowAnalSessShouldEnd_S__table_mrd_pcv_1qb__entry__2}

| 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 |
[Tabela 8. Retorna]

{#NAnServDel-nowAnalSessShouldEnd_S__table_mrd_pcv_1qb}  
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) {#ariaid-title6}

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.
{#NAnServDel-nowAnalSessShouldStart_S__table_ojw_z1v_1qb__entry__3}

| Nome | Tipo | Descrição |
|-|-|-|
| sessionId | Cadeia de caracteres | Identificador exclusivo da sessão a ser verificada. |
[Tabela 9. Parâmetros]

{#NAnServDel-nowAnalSessShouldStart_S__table_ojw_z1v_1qb} {#NAnServDel-nowAnalSessShouldStart_S__table_pjw_z1v_1qb__entry__2}

| Tipo | Descrição |
|-|-|
| Nenhum(a) |   |
[Tabela 10. Retorna]

{#NAnServDel-nowAnalSessShouldStart_S__table_pjw_z1v_1qb}  
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)


