Skip to main content

UI Kit App

Below are the various processes involved in setting up SpotChecks in UI Kit

Latest Version: 3.0.4

Installation​

The SurveySparrowSdk package can also be added by navigating to your target's General panel -> In the “Frameworks, Libraries, and Embedded Content” section, click on the + button -> select "Add Other "-> choose "Add Package Dependency" -> Enter the above package URL -> Click on Add Package.

Note: To use camera and voice transcription features, add the following lines in your app’s Info.plist file:

Camera Access​

<key>NSCameraUsageDescription</key>
<string>REASON</string>

Voice Transcription Support​

<key>NSMicrophoneUsageDescription</key>
<string>REASON</string>

<key>NSSpeechRecognitionUsageDescription</key>
<string>REASON</string>

Pre-requisites​

Ensure that all the screens are wrapped within the Navigation Controller or Tab Bar Controller

Initialization​

Import the SurveySparrowSdk and initialize a variable named spotCheck.

import SurveySparrowSdk

Anonymous users​

If you wish not to keep track of users' data, you can follow the below syntax for initialization.


var spotCheck = Spotcheck (
domainName: "<your_domain>",
targetToken: "<target_token>",
userDetails: [:],
variables: [:],
customProperties: [:],
sparrowLang: "ta", // Eg: ta, en
isUIKitApp: true
)

Known Users​

If you wish to keep track of users' data and perform conditional Survey triggers, you can follow the below syntax for initialization.

var spotCheck = Spotcheck (
domainName: "<your_domain>",
targetToken: "<target_token>",
userDetails: [
email: 'example@email.com',
firstName: '<your-first-name>',
lastName: '<your-last-name>',
mobile: '<user_mobile>',
uuid: '<uuid_value>' // Optional
],
variables: [
<api_identifier_of_variable>: '<variable_value>',
],
customProperties: [
<custom_property_name>:'<value>'
],
sparrowLang: "ta", // Eg: ta, en
isUIKitApp: true
)

Screen Track​

It provides the ability to keep track of screens the users are visiting and to enable the survey trigger on that screen.

  • For every screen, it is required to override the viewDidAppear method and use the TrackScreen functionality within the method.

Syntax:​

 override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)

spotCheck.TrackScreen(screen: "your_screen_name") {
trackScreenPassed in
if trackScreenPassed {
let hostingController = UIHostingController(rootView: spotCheck)
hostingController.modalPresentationStyle = .overFullScreen
hostingController.view.backgroundColor = UIColor.clear
self.present(hostingController, animated: true, completion: {})
}
}
}

Example:​

If a survey needs to be triggered on the payment page, the name of the ScreenName should be specified in the TrackScreen function.

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)

spotCheck.TrackScreen(screen: "PaymentScreen") {
trackScreenPassed in
if trackScreenPassed {
let hostingController = UIHostingController(rootView: spotCheck)
hostingController.modalPresentationStyle = .overFullScreen
hostingController.view.backgroundColor = UIColor.clear
self.present(hostingController, animated: true, completion: {})
}
}
}

Event Track​

It provides the ability to keep track of events which when triggered, will enable the survey to be popped.

Syntax:​

spotCheck.TrackEvent(
onScreen: "<your-screen-name>",
event: [
"<your-events-or-functions>":[:] //eg. "onButtonPressed": [:]
]){
trackScreenPassed in
if trackScreenPassed {
let hostingController = UIHostingController(rootView: spotCheck)
hostingController.modalPresentationStyle = .overFullScreen
hostingController.view.backgroundColor = UIColor.clear
self.present(hostingController, animated: true, completion: {})
}
}

Example:​

If a survey needs to be triggered when the user completes a payment, then the TrackEvent function should be called with the respective ScreenName and optional custom properties.

spotCheck.TrackEvent(
onScreen: "PaymentScreen",
event: [
"paymentComplete": [
"email" : "[email protected]",
"paymentStatus" : true
]
]){
trackScreenPassed in
if trackScreenPassed {
let hostingController = UIHostingController(rootView: spotCheck)
hostingController.modalPresentationStyle = .overFullScreen
hostingController.view.backgroundColor = UIColor.clear
self.present(hostingController, animated: true, completion: {})
}
}
Make sure to have the eventName configured in the Checks section of the configure panel

Callbacks (Optional)​

Callbacks are used to listen to events that are part of the SpotChecks. All callback functions are optional — you can implement only the ones you need. The available callbacks include:

  • Survey Response - triggers when the user submits a response.

  • Survey Loaded - triggers when the SpotChecks is loaded on the user's page.

  • Survey Close - triggers when the SpotChecks is closed by the user.

  • Partial Submission - triggers when the PartialSubmission is enabled and recieved.

Syntax:​

// Step 1: Add callbacks to the SpotChecks Initialization
var spotCheck = Spotcheck(
//...
surveyDelegate: SsDelegate()
)

// Step 2: Listen to the SpotChecks events
class SsDelegate: UIViewController, SsSpotcheckDelegate {
func handleSurveyResponse(response: [String : AnyObject]) async {}

func handleSurveyLoaded(response: [String : AnyObject]) async {}

func handleCloseButtonTap() async {}

func handlePartialSubmission(response: [String : AnyObject]) async {}
}