import UIKit
import PulseInsights
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var pulseInsights: PulseInsights?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialize PulseInsights with your Account ID
let accountId = "YOUR_ACCOUNT_ID"
pulseInsights = PulseInsights(accountId, enableDebugMode: true)
// Optional: Set custom host if needed
// pulseInsights?.setHost("survey.pulseinsights.com")
// Optional: Set custom data
let customData = ["user_type": "tester", "platform": "iOS"]
pulseInsights?.setContextData(customData)
return true
}
}// In your view controller
import PulseInsights
class YourViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Set the view name for targeting
PulseInsights.getInstance.setViewName("mainView", controller: self)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Serve the survey
PulseInsights.getInstance.serve()
}
}// Set the client key
PulseInsights.getInstance.setClientKey("YOUR_CLIENT_KEY")// Add context data
let contextData = ["user_id": "12345", "subscription_level": "premium"]
PulseInsights.getInstance.setContextData(contextData)
// Clear context data
PulseInsights.getInstance.clearContextData()