> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmonita.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Set Up Global Monitoring - iOS Swift SDK

> This is a step by step guide to setup and manage Monita Global Monitoring Setup/Manage Global Monitoring for iOS Swift

Global Monitoring is an Enterprise feature, which enables companies to agnostically monitor network requests departing your client.

### Instructions

1. Click 'New Domain' and your domain and select the Monitoring Tab
   <img src="https://mintcdn.com/monita/JXGAxnpYvkMASBZc/images/monitoring/global-monitoring-add-ios-android.png?fit=max&auto=format&n=JXGAxnpYvkMASBZc&q=85&s=32aebeb322609b0cf393e554411fc21c" alt="" width="932" height="818" data-path="images/monitoring/global-monitoring-add-ios-android.png" />
2. Select iOS SDK or Global Monitoring (Use Global if you would like to use the same Domain for both web and mobile)
3. Next provide the Domain you wish to ingest events from and press enter (you can add subdomains here)
   <img src="https://mintcdn.com/monita/9ogF6z6ScgRhVl-N/images/monitoring/global-monitoring-enter-domain.png?fit=max&auto=format&n=9ogF6z6ScgRhVl-N&q=85&s=317f53e8dc1c084e8f4006557701c890" alt="Add domain" width="1224" height="744" data-path="images/monitoring/global-monitoring-enter-domain.png" />
4. Start adding Vendors by Clicking new Vendor
   <img src="https://mintcdn.com/monita/9ogF6z6ScgRhVl-N/images/monitoring/global-monitoring-vendor-list-screen.png?fit=max&auto=format&n=9ogF6z6ScgRhVl-N&q=85&s=f25e655df6492b30d6e7f17d92bc017a" alt="Vendor List" width="2560" height="1221" data-path="images/monitoring/global-monitoring-vendor-list-screen.png" />
5. Search for an existing Vendor or create a Custom Vendor
   <Frame caption="Create a custom vendor">
     <img src="https://mintcdn.com/monita/JXGAxnpYvkMASBZc/images/monitoring/global-monitoring-add-custom-vendor.png?fit=max&auto=format&n=JXGAxnpYvkMASBZc&q=85&s=b2f8ec117a7594045b012ebe025fa040" alt="Add custom vendor" width="988" height="246" data-path="images/monitoring/global-monitoring-add-custom-vendor.png" />
   </Frame>
   <Frame caption="Search for existing providers">
     <img src="https://mintcdn.com/monita/JXGAxnpYvkMASBZc/images/monitoring/global-monitoring-add-existing-vendor.png?fit=max&auto=format&n=JXGAxnpYvkMASBZc&q=85&s=8964750927a1546b4cf019ca17a2997d" alt="Add existing vendor" width="926" height="304" data-path="images/monitoring/global-monitoring-add-existing-vendor.png" />
   </Frame>
6. Fill in the Monitoring Form for the specific Vendor you have Chosen
   <img src="https://mintcdn.com/monita/9ogF6z6ScgRhVl-N/images/monitoring/global-monitoring-vendor-config.png?fit=max&auto=format&n=9ogF6z6ScgRhVl-N&q=85&s=5efef7d013fb47d0afb032951a07b538" alt="Vendor configuration screen" width="1024" height="635" data-path="images/monitoring/global-monitoring-vendor-config.png" />
   The form has several crucial fields to complete:

<AccordionGroup>
  <Accordion title="Domains">
    This is the domain which client side pixel/tag requests are sent to.
    Typically known as the request URL e.g. for Facebook, "facebook.com/tr".
  </Accordion>

  <Accordion title="Execluded Parameters">
    Use this field to specify which keys you would like to exclude from monitoring. e.g. Facebook sends an "sw" parameter with screen width. If you don't want/need to monitor that key, enter it here.
  </Accordion>

  <Accordion title="Event Mapping Field">
    Used to specify which key in the vendors payload corresponds to the event name.
    You can specify either a single field by name, or multiple fields inside curly braces e.g. `{{fieldA}}-{{fieldB}}`. Here is an example request with the event in the "ev" parameter:

    <img src="https://mintcdn.com/monita/9ogF6z6ScgRhVl-N/images/monitoring/global-monitoring-custom-event-field.png?fit=max&auto=format&n=9ogF6z6ScgRhVl-N&q=85&s=583f58b0ce805e8c59af28263ccf8b0b" alt="Mapped event examples" width="131" height="97" data-path="images/monitoring/global-monitoring-custom-event-field.png" />

    You can also extract a field value via regular-expression.

    E.g. You may want to extract a sub-domain from a URL and add it to the event, this can be done by find inf the correct regex and applying it to the field parameter in the following format:

    `regex::(?<=https:\/\/)[\w|-]*::url`

    This format represents 3 sections, separated by double-colons (`::`). The 3 sections are:

    * `regex` which inpforms the expression parser that the user is passing a regex expression
    * `(?<=https:\/\/)[\w|-]*` is the regular expression  itself (javascript regex supported. Test your regex in any regex editor such are [Regexr](https://regexr.com/))
    * `url` is the field from which the content is extracted. You may use a dot (`.`) separated field path. (`url`, `host`, `method` and `vendorName` are automatically added to the payload)

    The following execnt field `eve-{{regex::(?<=https:\/\/)[\w|-]*::url}}` (multiple digits) on value of field "myfield". In a payload `{ url: "https://subdomain.myapp.com" }`, the event field will be `eve-subdomain`.

    <Tip>Regular Expression allows for capturing text in relation to the existence of other text before it or after it. This is called [lookahead](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookahead_assertion) and [lookbehind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookbehind_assertion)</Tip>
  </Accordion>

  <Accordion title="Filters">
    Use this to focus your monitoring to specific vendor requests e.g. only where "ev" = "orderSuccess". This can also help reduce API call consumption.
  </Accordion>
</AccordionGroup>

7. After completing your Vendor Form press the Apply and then the Save button. To Manage simply enter this form again, edit and you will notice the Deployment Version at the bottom increment by 1.
   <img src="https://mintcdn.com/monita/JXGAxnpYvkMASBZc/images/monitoring/global-monitoring-added-vendor.png?fit=max&auto=format&n=JXGAxnpYvkMASBZc&q=85&s=21d6b0fc5e71a8bdf5096590ee155975" alt="Vendor added to list" width="2560" height="1252" data-path="images/monitoring/global-monitoring-added-vendor.png" />
8. See the below iOS Swift installation guide to install the iOS SDK on your Swift App.

## Installation

Follow these steps to integrate Monita SDK into your iOS project:

### Step 1: Add the Package Dependency

1. Open Xcode and navigate to **File > Swift Packages > Add Package Dependency**.
2. In the search box, enter the URL:
   ```
   https://github.com/rnadigital/monita-ios-sdk.git
   ```
3. Click **Next**.
4. Select the **branch** option and enter `master` as the branch name.
5. Click **Finish**. The SDK will be added under **Swift Package Dependencies**.

### Step 2: Configure the SDK Token

1. Open your project's `Info.plist` file in Xcode.
2. Add a new key called `MonitaSDKToken` with your SDK token as the value:

   ```xml theme={null}
   <key>MonitaSDKToken</key>
   <string>Your-Token-Here</string>
   ```

## Usage

After installing the SDK, initialize it in your application delegate. For example, update your `AppDelegate.swift` as follows:

```swift theme={null}
import MonitaSDK

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Initialize Monita SDK with your custom configuration
    MonitaSDK.configure(
        enableLogger: true,
        batchSize: 10,
        customerId: "123456",
        consentString: "Granted",
        sessionId: "123456",
        appVersion: "1.0"
    )
    
    return true
}
```
