NowAnalyticsServiceProtocole Delegate : iOS

  • Rversion finale: Zurich
  • Mis à jour 31 juil. 2025
  • 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 : String)

    Notifie lorsqu’un changement d’écran est détecté. Le nom de l’écran est détecté dans la barre de navigation. Si cela n’est pas possible, il s’agit du nom de la sous-classe viewController.

    Tableau 1. Paramètres
    Nom Type Description
    nom d’écran Chaîne Nom de l’écran pour détecter tout changement.
    Tableau 2. Renvoie
    Type Description
    Chaîne Nom personnalisé à utiliser pour remplacer le screenName transmis.

    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 : String)

    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.

    Tableau 3. Paramètres
    Nom Type Description
    sessionId Chaîne Identificateur unique de la session à vérifier.
    Tableau 4. Renvoie
    Type Description
    Aucun

    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)

    Notifie lorsque la session spécifiée a commencé.

    Il s’agit d’une fonction de rappel qui est appelée lorsque la session spécifiée démarre réellement.

    Tableau 5. Paramètres
    Nom Type Description
    sessionId Chaîne Identificateur unique de la session à vérifier.
    Tableau 6. Renvoie
    Type Description
    Booléen Marqueur indiquant que la session est en cours de démarrage.
    Valeurs valides :
    • vrai : la session commence
    • faux : la session ne démarre pas

    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)

    Notifie lorsque 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.

    Tableau 7. Paramètres
    Nom Type Description
    sessionId Chaîne Identificateur unique de la session à vérifier.
    Tableau 8. Renvoie
    Type Description
    Booléen Marqueur indiquant que la session est en cours de fin.
    Valeurs valides :
    • vrai : la session se termine
    • faux : la session ne se termine pas

    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)

    Notifie si la session spécifiée est sur le point de démarrer.

    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.

    Tableau 9. Paramètres
    Nom Type Description
    sessionId Chaîne Identificateur unique de la session à vérifier.
    Tableau 10. Renvoie
    Type Description
    Aucun

    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)