---
sourceDocument: Référence de l’API Xanadu
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/fr-FR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - fr-FR

ft:publication_title :

    - Référence de l’API Xanadu

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Protocole NowAnalyticsServiceDelegate : iOS

# Protocole NowAnalyticsServiceDelegate : iOS {#ariaid-title1}

* Rversion finale: Xanadu
* 
* Mis à jour 1 août 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 5 minutes de lecture

Le protocole NowAnalyticsServiceDelegate fournit des fonctions de rappel qui fournissent des informations sur le démarrage et la fin d'une session utilisateur et la détection des changements d'écran.

## NowAnalyticsServiceDelegate : nowAnalyticsDidDetectScreen( _ sessionId : chaîne) {#ariaid-title2}

Notifie lorsqu'un changement d'écran est détecté. Le nom de l'écran est détecté à partir de la barre de navigation. Si ce n'est pas possible, c'est le nom de la sous-classe viewController.
{#NAnServDel-nowAnalDidDetectScreen_S__table_ljr_3bb_kqb__entry__3}

| Nom | Type | Description |
|-|-|-|
| screenName | Chaîne | Nom de l'écran permettant de détecter s'il y a un changement. |
[Tableau 1. Paramètres]

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

| Type | Description |
|-|-|
| Chaîne | Nom personnalisé à utiliser pour remplacer le screenName transmis. |
[Tableau 2. Renvoie]

{#NAnServDel-nowAnalDidDetectScreen_S__table_mjr_3bb_kqb}  
Cet exemple montre comment définir une classe de délégué pour 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 : chaîne) {#ariaid-title3}

Notifie lorsque la session spécifiée est terminée.
Il s'agit d'une fonction de rappel qui est appelée lorsque la session spécifiée se termine réellement.
{#NAnServDel-nowAnalSessionDidEnd_S__table_hnt_b2v_1qb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sessionId | Chaîne | Identificateur unique de la session à vérifier. |
[Tableau 3. Paramètres]

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

| Type | Description |
|-|-|
| Aucun |   |
[Tableau 4. Renvoie]

{#NAnServDel-nowAnalSessionDidEnd_S__table_int_b2v_1qb}  
Cet exemple montre comment définir une classe de délégué pour 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 : chaîne) {#ariaid-title4}

Notifie lorsque la session spécifiée a démarré.
Il s'agit d'une fonction de rappel qui est appelée lorsque la session spécifiée démarre réellement.
{#NAnServDel-nowAnalSessionDidStart_S__table_ntx_m2v_1qb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sessionId | Chaîne | Identificateur unique de la session à vérifier. |
[Tableau 5. Paramètres]

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

| Type | Description |
|-|-|
| Booléen | Marqueur qui indique que la session est en cours de démarrage. Valeurs valides : * true : la session commence * false : la session ne démarre pas |
[Tableau 6. Renvoie]

{#NAnServDel-nowAnalSessionDidStart_S__table_otx_m2v_1qb}  
Cet exemple montre comment définir une classe de délégué pour 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 : chaîne) {#ariaid-title5}

Notifie quand la session spécifiée est sur le point de se terminer.
Il s'agit d'une fonction de rappel qui est appelée lorsque la session spécifiée est sur le point de se terminer.
{#NAnServDel-nowAnalSessShouldEnd_S__table_lrd_pcv_1qb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sessionId | Chaîne | Identificateur unique de la session à vérifier. |
[Tableau 7. Paramètres]

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

| Type | Description |
|-|-|
| Booléen | Marqueur indiquant que la session se termine. Valeurs valides : * true : la session se termine * false : la session ne se termine pas |
[Tableau 8. Renvoie]

{#NAnServDel-nowAnalSessShouldEnd_S__table_mrd_pcv_1qb}  
Cet exemple montre comment définir une classe de délégué pour 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 : chaîne) {#ariaid-title6}

Notifie si la session spécifiée est sur le point de commencer.
Il s'agit d'une fonction de rappel qui est appelée lorsque la session spécifiée est sur le point de démarrer.
{#NAnServDel-nowAnalSessShouldStart_S__table_ojw_z1v_1qb__entry__3}

| Nom | Type | Description |
|-|-|-|
| sessionId | Chaîne | Identificateur unique de la session à vérifier. |
[Tableau 9. Paramètres]

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

| Type | Description |
|-|-|
| Aucun |   |
[Tableau 10. Renvoie]

{#NAnServDel-nowAnalSessShouldStart_S__table_pjw_z1v_1qb}  
Cet exemple montre comment définir une classe de délégué pour 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)


