Implement the Network Request Callback

The callback that modifies or ignore specific URLs is an implementation of the protocol below. The callback method networkRequestCallback is synchronous, so it is recommended that you return from the function quickly.

CODE
- (BOOL)networkRequestCallback:(ADEumHTTPRequestTracker *)networkRequest

Transforming URLs

The networkRequestCallback method, in general, should follow the steps below to transform URLs:

  1. Identify specific URLs using techniques such as regex or pattern matching.
  2. Modify the url property of the ADEumHTTPRequestTracker object. (Modifying other properties of the ADEumHTTPRequestTracker object will be ignored).
  3. Assign a valid URL to the url property.
  4. If you need the request and response headers, use the following fields:
    • allHeaderFields - It returns the response headers.

    • allRequestHeaderFields - It returns the request headers.

  5. Return YES (Objective-C) or true (Swift).

The first step is optional as you could choose to transform the URLs of all network requests.

Objective-C
JSON
- (BOOL)networkRequestCallback:(ADEumHTTPRequestTracker *)networkRequest
{
    NSString *maskURL = @"http://networkrequest-mask.com";
    NSURL *url = [NSURL URLWithString:maskURL];
    networkRequest.url = url;
    return YES;
}
Swift
JAVASCRIPT
func networkRequestCallback(_ networkRequest: ADEumHTTPRequestTracker?) -> Bool {
    let maskURL = "http://networkrequest-mask.com"
    let url = URL(string: maskURL)
    networkRequest?.url = url
    return true
}
In general, however, you would want to identify and transform URLs that contain sensitive information as implied in the example below:
Objective-C
JSON
- (BOOL)networkRequestCallback:(ADEumHTTPRequestTracker *)networkRequest
{
    NSString *urlString = networkRequest.url.absoluteString;
    BOOL returnBeacon = YES;
    NSString *maskURL = @"http://customer-account.com";
    if (!([urlString rangeOfString:@"accountInfo"].location == NSNotFound)) {
        networkRequest.url = [NSURL URLWithString:maskURL];
    }
    return returnBeacon;
}
Swift
JAVASCRIPT
func networkRequestCallback(_ networkRequest: ADEumHTTPRequestTracker?) -> Bool {
    let urlString = networkRequest?.url.absoluteString
    returnBeacon = true
    let maskURL = "http://customer-account.com"
    if !(Int((urlString as NSString?)?.range(of: "accountInfo").location ?? 0) == NSNotFound) {
        networkRequest?.url = URL(string: maskURL)
    }
    return returnBeacon
}

Ignoring URLs

If the networkRequestCallback method returns false, the beacon is dropped. The general process for ignoring beacons is as follows:

  1. Identify specific URLs using techniques such as regex or pattern matching.

  2. Return false.

You could theoretically ignore all network requests by having the callback networkRequestCallback always return NO (Objective-C) or false (Swift):

Objective-C
JSON
- (BOOL)networkRequestCallback:(ADEumHTTPRequestTracker *)networkRequest
{
    return NO;
}
Swift
JSON
func networkRequestCallback(_ networkRequest: ADEumHTTPRequestTracker?) -> Bool {
    return false
}
In general, though, you would identify network requests that you didn't want to monitor and return NO (Objective-C) or false (Swift) to ignore the network request as implied by this example.
Objective-C
JSON
- (BOOL)networkRequestCallback:(ADEumHTTPRequestTracker *)networkRequest
{
    NSString *urlString = networkRequest.url.absoluteString;
    BOOL returnBeacon = YES;
    if (!([urlString rangeOfString:@"avatar"].location == NSNotFound)) {
        returnBeacon = NO;
    }
    return returnBeacon;
}
Swift
JAVASCRIPT
func networkRequestCallback(_ networkRequest: ADEumHTTPRequestTracker?) -> Bool {
    let urlString = networkRequest?.url.absoluteString
    var returnBeacon = true
    if !(Int((urlString as NSString?)?.range(of: "avatar").location ?? 0) == NSNotFound) {
        returnBeacon = false
    }
    return returnBeacon
}