-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #729 from DataDog/feature/hybrid-application
- Loading branch information
Showing
40 changed files
with
1,539 additions
and
178 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-2020 Datadog, Inc. | ||
*/ | ||
|
||
import UIKit | ||
import Datadog | ||
|
||
private struct WebViewTrackingScenarioPredicate: UIKitRUMViewsPredicate { | ||
private let defaultPredicate = DefaultUIKitRUMViewsPredicate() | ||
|
||
func rumView(for viewController: UIViewController) -> RUMView? { | ||
if viewController is ShopistWebviewViewController { | ||
return nil // do not consider the webview itself as RUM view | ||
} else { | ||
return defaultPredicate.rumView(for: viewController) | ||
} | ||
} | ||
} | ||
|
||
final class WebViewTrackingScenario: TestScenario { | ||
static var storyboardName: String = "WebViewTrackingScenario" | ||
|
||
func configureSDK(builder: Datadog.Configuration.Builder) { | ||
_ = builder | ||
.trackUIKitRUMViews(using: WebViewTrackingScenarioPredicate()) | ||
.enableLogging(true) | ||
.enableRUM(true) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Datadog/Example/Scenarios/WebView/WebViewTrackingFixtureViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-2020 Datadog, Inc. | ||
*/ | ||
|
||
import UIKit | ||
import WebKit | ||
import Datadog | ||
|
||
class WebViewTrackingFixtureViewController: UIViewController, WKNavigationDelegate { | ||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
|
||
// An action sent from native iOS SDK. | ||
Global.rum.addUserAction(type: .custom, name: "Native action") | ||
|
||
// Opens a webview configured to pass all its Browser SDK events to native iOS SDK. | ||
show(ShopistWebviewViewController(), sender: nil) | ||
} | ||
} | ||
|
||
class ShopistWebviewViewController: UIViewController { | ||
private let request = URLRequest(url: URL(string: "https://shopist.io")!) | ||
private var webView: WKWebView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
let controller = WKUserContentController() | ||
controller.trackDatadogEvents(in: ["shopist.io"]) | ||
let config = WKWebViewConfiguration() | ||
config.userContentController = controller | ||
|
||
webView = WKWebView(frame: UIScreen.main.bounds, configuration: config) | ||
view.addSubview(webView) | ||
} | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
webView.load(request) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Datadog/Example/Scenarios/WebView/WebViewTrackingScenario.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Y6W-OH-hqX"> | ||
<device id="retina6_1" orientation="portrait" appearance="light"/> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="System colors in document resources" minToolsVersion="11.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Web View Tracking Fixture View Controller--> | ||
<scene sceneID="s0d-6b-0kx"> | ||
<objects> | ||
<viewController id="Y6W-OH-hqX" customClass="WebViewTrackingFixtureViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc"> | ||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/> | ||
<color key="backgroundColor" systemColor="systemBackgroundColor"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="114" y="80"/> | ||
</scene> | ||
</scenes> | ||
<resources> | ||
<systemColor name="systemBackgroundColor"> | ||
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | ||
</systemColor> | ||
</resources> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2019-2020 Datadog, Inc. | ||
*/ | ||
|
||
import Foundation | ||
|
||
internal protocol HostsSanitizing { | ||
func sanitized(hosts: Set<String>, warningMessage: String) -> Set<String> | ||
} | ||
|
||
internal struct HostsSanitizer: HostsSanitizing { | ||
func sanitized(hosts: Set<String>, warningMessage: String) -> Set<String> { | ||
let urlRegex = #"^(http|https)://(.*)"# | ||
let hostRegex = #"^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)+([A-Za-z]|[A-Za-z][A-Za-z0-9-]*[A-Za-z0-9])$"# | ||
let ipRegex = #"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"# | ||
|
||
var warnings: [String] = [] | ||
|
||
let array: [String] = hosts.compactMap { host in | ||
if host.range(of: urlRegex, options: .regularExpression) != nil { | ||
// if an URL is given instead of the host, take its `host` part | ||
if let sanitizedHost = URL(string: host)?.host { | ||
warnings.append("'\(host)' is an url and will be sanitized to: '\(sanitizedHost)'.") | ||
return sanitizedHost | ||
} else { | ||
warnings.append("'\(host)' is not a valid host name and will be dropped.") | ||
return nil | ||
} | ||
} else if host.range(of: hostRegex, options: .regularExpression) != nil { | ||
// if a valid host name is given, accept it | ||
return host | ||
} else if host.range(of: ipRegex, options: .regularExpression) != nil { | ||
// if a valid IP address is given, accept it | ||
return host | ||
} else if host == "localhost" { | ||
// if "localhost" given, accept it | ||
return host | ||
} else { | ||
// otherwise, drop | ||
warnings.append("'\(host)' is not a valid host name and will be dropped.") | ||
return nil | ||
} | ||
} | ||
|
||
warnings.forEach { warning in | ||
consolePrint( | ||
""" | ||
⚠️ \(warningMessage): \(warning) | ||
""" | ||
) | ||
} | ||
|
||
return Set(array) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.