Enable Users to Accept Offer

This section describes how to enable your users to accept an offer, and includes the following topics:

Enable Users to Accept Offer

Enable Users to Accept Offer

1.0. Submit User Info to adClickRedirection API

Submit the user’s personal information to the adClickRedirection v3 (GET) endpoint. This endpoint is received in the button_click_url field of the adUnit v2 response. The button_click_url comes pre-populated with authentication information so no API KEY is required to call this endpoint. Therefore this API call can be directly made by the mobile clients to the IQL server without the intervention of the publisher’s backend.

Click here to read the documentation for the adClickRedirection v3 API.

Create a base64 encoded payload with the information provided by the user. Replace the <payload>string in buttonClickURL received in the adUnitDetails API with the generated payload. Load it using the in-app browser, that is, SFSafariViewController, as given in the following code snippet.

extension UserInfoViewController {
    ...
    @objc func onContinueClicked() {
        openUrlRequest()
    }
    func saveUserInfoData() {
        let zipcodeInfo = ZipCodeUtils.sharedInstance.getDriverProvince(zipcode: Int(zipcodeTF.text!)!)
        core.loginRepository.saveUserInfo(firstName: firstNameTF.text!, lastName: lastNameTF.text!, email: emailTF.text!, dob: dobTF.text!, streetName: streetTF.text!, city: cityTF.text!)
        core.loginRepository.updateUserLocationData(zipcode: zipcodeTF.text!, stateCode: zipcodeInfo.shortHand, countryCode: insurerRepository.userData.countryCode)
    }
    func openUrlRequest() {
        if NetworkUtils.isNetworkConnected() {
            saveUserInfoData()
            if let url = createPayloadUrl() {
                openInAppBrowser(url: url)
            }
        } else {
            showNeworkAlert()
        }
    }
    func createPayloadUrl() -> URL? {
        guard let adUnitDetails = core.iqlAdUnitRepository.getAdUnitDetails() else {
            fatalError("AdUnit details does not exist")
        }
        let adClickUrlString = adUnitDetails.adUnit.buttonClickUrl
        let stateCode = StateDirectory.sharedInstance.getStateShortHand(stateName: selectedStateName)!
        let dateString = DateUtils.sharedInstance.getDOBString(inputDate: dateOfBirth, uploadDate: true)
        let addressDict : [String: String] = [ "street": streetTF.text!, "city": cityTF.text!, "state_code": stateCode, "zipcode": zipcodeTF.text! ]
        let dataDict : [String: Any] = [ "first_name": firstNameTF.text!, "last_name": lastNameTF.text!, "email_address": emailTF.text!, "address": addressDict, "DOB": dateString]
        let base64String =  createPayloadString(dataDict: dataDict)
        let urlString = adClickUrlString.replacingOccurrences(of: "<payload>", with: base64String)
        if let url = URL(string: urlString) {
            return url
        }
        return nil
    }
    func openInAppBrowser(url: URL) {
        let vc = SFSafariViewController(url: url)
        self.present(vc, animated: true)
    }
    func createPayloadString(dataDict: [String: Any]) -> String {
        do {
            let jsonData = try JSONSerialization.data(withJSONObject: dataDict, options: .prettyPrinted)
            if let jsonString = String(data: jsonData,
                                       encoding: .utf8) {
                if let utfString = jsonString.data(using: .utf8) {
                    return utfString.base64EncodedString().encodedUrl ?? ""
                }
            }
        } catch {
            DDLogDebug("Error while creating base64 string - \(error.localizedDescription)")
        }
        return ""
    }
    ...
}ob

2.0. Publisher Integration Testing Checklist

Use the following testing checklist to verify that the user is enabled to accept the offer:

  • Ensure that the user is redirected to the insurer's website correctly and that the in-app browser or webview experience is working smoothly. Check that the user is able to successfully submit any missing details.