Manual Integration

Manual integration involves the following simple steps:

  1. SDK Initialization
    Initialize the SDK
  2. Getting Headers
    Get DataDome headers to add in your request headers
  3. Verify Response
    When the request is completed, verify if it is a DataDome response or not
  4. Handle DataDome response
    If it is a DataDome response, handle it using the SDK
This integration is useful in some specific cases:
  • Integration in a complex architecture
  • Integration in a project with several different HTTP clients or network layers
  • Integration in a project using another HHP client that is not yet supported
However, we strongly recommend using URLSession, Moya or Alamofire integration whenever possible.

1 - DataDome SDK Initalization

First of all, you need to declare a DataDomeSDK var:

var dataDomeSdk: DataDomeSDK?

The next step is to initialize the DataDomeSDK:

override func viewDidLoad() {

	super.viewDidLoad()
        
	// Init
	dataDomeSdk = DataDomeSDK(containerView: 
                            containerView, 
                            key: "Client_Side_Key", 
                            appVersion: appVersion, 
                            userAgent: useragent,
                           integrationMode: .manual)
	// Set the delegate
	dataDomeSdk?.delegate = self
}

2 - DataDome Headers

Following the SDK initialization, get the DataDome headers to add in your request:

override func viewDidLoad() {

	super.viewDidLoad()
  
	// After sdk initialized
	// Get the DataDome headers to add in your request
  //
  // You can choose to have DataDome SDK UserAgent in headers with
  // withUserAgent parameter (optional, default value is false)
  //
	if let dataDomeHeaders = dataDomeSdk?.getHeaders() {
		// Add headers to your request
  }
}

3 - DataDome Verify response

After the request is completed, the next step is to verify if the response is a DataDome response or not, using the verifyResponse method:

func makeRequest(myUrl: URL) {
	let task = self.urlSession?.dataTask(with: request, completionHandler: { data, response, error in
		if self.dataDomeSdk?.verifyResponse(statusCode: httpResponse.statusCode,
                                        headers: httpResponse.allHeaderFields,
                                        url: url) {
			
			// This is a DataDome response
		} else {
			// This is not a DataDome response
			// Do what you want and need with your response
		}
	})
	task?.resume()
}

4 - DataDome Handle response

When there is a DataDome response, you need to call handleResponse from the SDK to properly handle and manage the DataDome response and the Captcha.

func makeRequest(myUrl: URL) {
	let task = self.urlSession?.dataTask(with: request, completionHandler: { data, response, error in
		if self.dataDomeSdk?.verifyResponse(statusCode: httpResponse.statusCode,
                                        headers: httpResponse.allHeaderFields,
                                        url: url) {
			
			// This is a DataDome response
			self.dataDomeSdk?.handleResponse(statusCode: httpResponse.statusCode,
                                       headers: httpResponse.allHeaderFields,
                                       url: url,
                                       data: data,
                                       completion: { (completion, message) in
 
				switch completion {
				case .inProgress:
					// Called when a captcha is already in progress
				case .complete:
					// Called when captcha is completed
				case .error:
					// Called when captcha was canceled or encountered an error
				}
			})
 
		} else {
			// This is not a DataDome response
			// Do what you want and need with your response
		}
	})
	task?.resume()
}

DataDome SDK Listener

The DataDome Listener is optional and provides you with another way to get more information concerning request handling by the SDK with the Captcha lifecycle.

Below is the list of all the listeners provided by the DataDome SDK:

class ViewController: UIViewController, DataDomeSDKDelegate {

	override func viewDidLoad() {

		super.viewDidLoad()
		// Init of SDK and view here
		// And set the delegate
		dataDomeSDK.delegate = self
	}


	// MARK : - DataDomeSDKDelegate methods

	func captcha(_ instance: DataDomeSDK, willAppear webView: UIView?) {
		// Called when captcha will appear
	}

	func captcha(_ instance: DataDomeSDK, didAppear webView: UIView?) {
		// Called when captcha did appear
	}

	func captcha(_ instance: DataDomeSDK, willDisappear webView: UIView?) {
		// Called when captcha will disappear
	}

	func captcha(_ instance: DataDomeSDK, didDisappear webView: UIView?) {
		// Called when user successfully pass the captcha
 		// you can now re-send your request and get your data
	}

	func datadomeRespond(_ responseCode: Int, withData data: Any?) {
		// request was not blocked by DataDome
		// not used in manual integration
	}
}