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.
- (BOOL)networkRequestCallback:(ADEumHTTPRequestTracker *)networkRequest
Transforming URLs
The networkRequestCallback method, in general, should follow the steps below to transform URLs:
- Identify specific URLs using techniques such as regex or pattern matching.
- Modify the url property of the
ADEumHTTPRequestTrackerobject. (Modifying other properties of theADEumHTTPRequestTrackerobject will be ignored). - Assign a valid URL to the url property.
- If you need the request and response headers, use the following fields:
-
allHeaderFields- It returns the response headers. -
allRequestHeaderFields- It returns the request headers.
-
- 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 }
- 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:
-
Identify specific URLs using techniques such as regex or pattern matching.
- 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 }
- 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 }