---
title: Track Webviews - iOS
description: Track webviews with the Contentsquare iOS SDK
lastUpdated: 11 March 2026
source_url:
  html: https://docs.contentsquare.com/en/csq-sdk-ios/experience-analytics/track-webviews/
  md: https://docs.contentsquare.com/en/csq-sdk-ios/experience-analytics/track-webviews/index.md
---

iOS compatibility

Contentsquare **only** allows to track instances of `WKWebView`.\
`SFSafariViewController` is **not** supported: The Contentsquare SDK **cannot** track what is happening within its context, and its content will **not** be visible in Session Replay.

## Enable tracking in WebViews

### Where to inject your WebViews?

It is **essential** that you register your WebViews in `viewWillAppear()` and unregister them in `viewWillDisappear()`.

Additionally, when setting a delegate on your WebView, ensure that it is implemented and set **before** calling `CSQ.registerWebView(webView: WKWebView)`. If this order is not respected, your delegate will **not** receive any callbacks.

### WebView tracking lifecycle

Use the following APIs:

* Swift

  ```swift
  import ContentsquareSDK
  import WebKit


  // Register a WKWebView with ContentsquareSDK
  CSQ.registerWebView(webView)


  // Unregister a WKWebView with ContentsquareSDK
  CSQ.unregisterWebView(webView)
  ```

* Objective-C

  ```objective-c
  @import ContentsquareSDK;
  @import WebKit;


  // Register a WKWebView with ContentsquareSDK
  [CSQ registerWebView:webView];


  // Unregister a WKWebView with ContentsquareSDK
  [CSQ unregisterWebView:webView];
  ```

### Tag setup

To complete the implementation, inject the **CS Tag in WebView mode** on your pages.

See 📚 [Mobile Apps WebView Tracking Documentation](https://docs.contentsquare.com/en/webview-tracking-tag/#manual-injection).

## Full example

Here is a `UIViewController` implementation. Register the WebView in `viewWillAppear()` and unregister it in `viewWillDisappear()`:

* Swift

  ```swift
  override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(animated)


      // Inject the Bridge between the CS Tag in WebView mode and the SDK
      CSQ.registerWebView(webView)
  }


  override func viewWillDisappear(_ animated: Bool) {
      super.viewWillDisappear(animated)


      CSQ.unregisterWebView(webView)
  }
  ```

* Objective-C

  ```objective-c
  - (void)viewWillAppear:(BOOL)animated {
      [super viewWillAppear:animated];


      // Inject the Bridge between the CS Tag in WebView mode and the SDK
      [CSQ registerWebView:self.webView];
  }


  - (void)viewWillDisappear:(BOOL)animated {
      [super viewWillDisappear:animated];


      [CSQ unregisterWebView:self.webView];
  }
  ```

## Validate WebView tracking

### On the native side

Once you open the screen with the tracked WebView in your app, you should see the following log:

```plaintext
CSLIB ℹ️ Info: WebView tracking enabled on native side for page: [URL]. Waiting for Web Tracking Tag messages…
```

Once the web page is loaded in the WebView, you should see the following log:

```plaintext
CSLIB ℹ️ Info: WebView navigated to new page: [URL]. Waiting for Web Tracking Tag messages…
```

### On the Web side

Once the Web Tracking tag is detected in the web page, you should see the following log:

```plaintext
CSLIB ℹ️ Info: Web Tracking Tag is detected on page: [URL]
```

#### Validating Pageview and Gestures tracking

* Page views sent through the Web Tracking Tag are displayed the same way as native screen views:

```plaintext
CSLIB ℹ️ Info: Screenview - Screen name: "{{page name given}}" - Screen number: 11
```

* Taps and swipes detected by the Web Tracking Tag are also displayed the same way as taps and swipe on native elements, but the end of the target contains HTML DOM elements:

```plaintext
CSLIB ℹ️ Info: Tap - Target: ...>UIViewControllerWrapperView:eq(0)>UIView:eq(0)>WKWebView:eq(0)|webview|img#picture-holder
```
