Advanced Integrations

1. Event Logging (Analytics / Triggers)

You can send events to the platform while a user session is active (after setUser). If there is no active session, the call is silently ignored.

KLP.shared.logEvent(eventName: "LogIn")
KLP.shared.logEvent(eventName: "MoneyTransfer", attributes: ["Quantity": 50])

KLP.shared.logEncryptedEvent(eventName: "LogIn")
KLP.shared.logEncryptedEvent(
    eventName: "MoneyTransfer",
    attributes: ["Quantity": 50, "Currency": "TRY"]
)

Event names and attribute keys must be aligned with KLP / your backend according to your business rules.


2. Delegate (Optional)

Default behaviors (e.g. the SDK's own notification popup for SSE) are sufficient for most scenarios. Assign a KLPDelegate for custom flows; default empty implementations are provided for methods you don't define.

final class MyScreen: UIViewController, KLPDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
        KLP.shared.delegate = self
    }

    // Real-time effects from the server (points, mission progress, etc.)
    // Return true to suppress the SDK's default popup and handle the UI yourself.
    func klp(_ klp: KLP, didReceiveSSEEffects effects: [KLPSSEEffect]) -> Bool {
        return false
    }

    // Reward earned from within the WebView
    func klp(_ klp: KLP, didEarnReward reward: KLPReward) {
        print("Reward: \(reward.name)")
    }

    // WebView was closed
    func klpDidCloseWebView(_ klp: KLP) {}

    // Deep link requested from within the WebView
    // true: SDK closes the WebView; false: it stays open
    func klp(_ klp: KLP, didRequestDeepLink deepLink: KLPDeepLink) -> Bool {
        // Example: deepLink.queryParameters["symbol"]
        return true
    }
}

Other optional methods: didReceiveEvent, didFailWithError, didFailSecurityCheck.


3. Deep Link (Alternative Methods)

  1. Closure (most common):
KLP.shared.onDeepLink = { deepLink in
    // Handle your app navigation here
    return true // Return true if you want the WebView to close
}
  1. NotificationCenter (e.g. SwiftUI): Listen for the KLPNotification.deepLinkRequested notification; userInfo contains KLPNotification.deepLinkKey (KLPDeepLink) and KLPNotification.deepLinkURLKey (URL).