## Ad View Event  
An event that describes the action of seeing an ad.

### Example  
Here's an example of a _Ad View_:

- JavaScript  
- Swift  
- Kotlin

```javascript  
pcdp("event", "track", {  
  "clientId": "kevel",  
  "siteId": "kevel.com",  
  "type": "adView",  
  "customFields": {  
    "debug": "true",  
    "role": "superuser"  
  },  
  "campaignId": "ADWORDS_KEVEL_456",  
  "source": "g_adwords"  
})  
```

```swift  
import Foundation  
  
let event = """{  
  "clientId": "kevel",  
  "siteId": "kevel.com",  
  "type": "adView",  
  "customFields": {  
    "debug": "true",  
    "role": "superuser"  
  },  
  "campaignId": "ADWORDS_KEVEL_456",  
  "source": "g_adwords"  
}"""  
  
let trackUrl = "https://tr.cdp.\(websiteDomain)/events"  
  
var urlComponents = URLComponents(string: trackUrl)!  
  
urlComponents.queryItems = [\  
  URLQueryItem(name: "id_\(idType)", value: id),\  
  URLQueryItem(name: "cookies", value: "false")\  
]  
  
var request = URLRequest(url: urlComponents.url!)  
  
request.httpMethod = "POST"  
request.setValue("application/json", forHTTPHeaderField: "Content-Type")  
request.setValue(userAgent, forHTTPHeaderField: "User-Agent")  
request.httpBody = event.data(using: .utf8)!  
  
URLSession.shared.dataTask(with: request).resume()  
```

```kotlin  
import androidx.core.net.toUri  
import org.json.JSONObject  
import java.net.URL  
import javax.net.ssl.HttpsURLConnection  
  
val event = """{  
  "clientId": "kevel",  
  "siteId": "kevel.com",  
  "type": "adView",  
  "customFields": {  
    "debug": "true",  
    "role": "superuser"  
  },  
  "campaignId": "ADWORDS_KEVEL_456",  
  "source": "g_adwords"  
}"""  
  
val trackUri = "https://tr.cdp.$websiteDomain/events".toUri().buildUpon()  
    .appendQueryParameter("id_$idType", id)  
    .appendQueryParameter("cookies", "false")  
    // Network requests aren't allowed in main thread. Get adequate scope from context.  
    // See https://kotlinlang.org/docs/coroutines-guide.html for more info.  
coroutineScope.launch(Dispatchers.IO) {  
    val conn = (URL(trackUri.toString()).openConnection() as HttpsURLConnection).apply {  
        requestMethod = "POST"  
        setRequestProperty("User-Agent", userAgent)  
        setRequestProperty("Content-Type", "application/json")  
        doOutput = true  
    }  
    conn.outputStream.use { os ->  
        os.write(event.toByteArray(Charsets.UTF_8))  
    }  
    try {  
        // Trigger the request  
        conn.responseCode  
    } finally {  
        conn.disconnect()  
    }  
}  
```

### Supported Fields for Ad View  
In more detail, the fields supported on every _Ad View_ are:

| Field                           | Required | Type                             | Default | Example                 | Description                                                    |  
|---------------------------------|----------|----------------------------------|---------|-------------------------|---------------------------------------------------------------|  
| `clientId`                     |          | string                           |         | `"kevel"`             | The client identifier.                                       |  
| `siteId`                       |          | string                           |         | `"kevel.com"`         | The client's site identifier.                                 |  
| `type`                          | _required_ | `"adView"`                    |         | `"adView"`            | The event type.                                             |  
| `customFields`                 |          | object of string                |         | `{...}`                 | An object with custom fields for extra metadata to be supplied in the event. The values within this object must all be strings. |  
| `facebookConversionTracking`    |          | [Facebook Conversion Tracking Details](https://docs.audience.kevel.com/collect/events/adView#facebook-conversion-tracking-details) |         | [`{...}`](https://docs.audience.kevel.com/collect/events/adView#facebook-conversion-tracking-details) | A description of a tracking event to send to Facebook using Facebook Conversions API. |  
| `campaignId`                   |          | string                           |         | `"ADWORDS_KEVEL_456"` | The id of the advertising campaign the ad is associated with. |  
| `source`                        |          | string                           |         | `"g_adwords"`         | The source of the ad that was viewed.                        |  
 
### Facebook Conversion Tracking Details  
A description of a tracking event to send to Facebook using Facebook Conversions API.

| Field        | Required | Type          | Default | Example              | Description                                                                          |  
|--------------|----------|---------------|---------|----------------------|--------------------------------------------------------------------------------------|  
| `pixel_id`   |          | string        |         | `"396622227884531"` | The pixel ID to associate this Facebook tracking event with.                        |  
| `event_id`   |          | string        |         | `"0c53d0b57"`      | ID used to deduplicate events sent by both Facebook Pixel and Conversions API. More information about the usefulness of this ID is available at [Deduplicate Events](https://developers.facebook.com/docs/marketing-api/server-side-api/using-the-api/deduplicate-pixel-and-server-side-events). |  
| `event_name` |          | string        |         | `"AddToCart"`      | A Facebook pixel Standard Event or Custom Event name. This field is used to deduplicate events sent by both Facebook Pixel and Conversions API. The available Standard Events are listed in [Facebook Pixel Standard Events](https://developers.facebook.com/docs/facebook-pixel/reference#standard-events). |  
| `custom_data` |          | object        |         | `{...}`              | Parameters to send additional data Facebook can use for ads delivery optimization. More information about the fields that can be supplied here is available at [Custom Data](https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data). |
