# Data Collection for the Web SDK

Understand the types of data collected by the Web SDK.
## Privacy Manager

> **Important:** You are responsible for informing your end users about data collection, and
> collecting consent from the End User. The Airship SDK will perform data
> collection as described in this document on the signals provided by your
> integration, and you must collect the appropriate consent prior to using SDK
> features that perform data collection.
> 
> When the Airship SDK is loaded, either by inclusion of the snippet or import
> into a registered service worker, it will create databases and utility records
> in the browser. While these are non-identifying, if you require consent before
> any operation is performed, do not load the Airship SDK onto your pages
> until you have collected that consent.


Data collected by the Airship SDK can be controlled using Privacy Manager flags.
Each flag enables additional Airship features within the SDK and controls what
data is collected. The flags are for individual or groups of functional features
within the SDK. Some Airship features, such as contact tags, require enabling
multiple flags.

| Privacy Manager Flag | Features                                                                                                             |
|----------------------|----------------------------------------------------------------------------------------------------------------------|
| Push                 | Push notifications                                                                                                   |
| In-App Automation    | Scenes                                                                                                               |
| Tags and Attributes  | Tags, Attributes, and Subscription Lists                                                                             |
| Contacts             | Contact Tags, Attributes, and Subscription Lists; Named User; and Associated Channels                                |
| Analytics            | Associated identifiers, Custom events, Screen tracking, Surveys (questions and NPS surveys in [Scenes](https://www.airship.com/docs/reference/glossary/#scene)), email address (by using form inputs in Scenes), [Feature Flag](https://www.airship.com/docs/reference/glossary/#feature_flag) interaction |
| Feature Flags        | Feature Flag evaluation and interaction                                                                              |

### SDK Data Collection

All SDK features are enabled by default, but the SDK can be configured to
disable all or a subset of features on start. If the SDK is initialized without
any features enabled, it will not make any network requests. If the SDK features
are disabled after being previously enabled, it may make a few network requests
to opt the channel out to prevent notifications.

> **Note:** The data collected automatically by the SDK is not used to track users across
> websites or web applications.


| Data                          | Description                                                                                         | Privacy Manager Features     |
|-------------------------------|-----------------------------------------------------------------------------------------------------|------------------------------|
| Channel ID                    | Airship browser instance identifier                                                                 | *Any*                        |
| Locale                        | The browser's locale, comprised of language and language country                                    | *Any*                        |
| Time zone                     | The device time zone                                                                                | *Any*                        |
| SDK version                   | The Airship SDK version                                                                             | *Any*                        |
| Notification opt-In status    | Notifications and background opt-in status                                                          | *Any*                        |
| Contact ID                    | Internal Airship ID that maps to contact                                                            | Contacts                     |
| Push Subscription             | The VAPID push subscription and endpoints                                                           | Push                         |
| Push Platform                 | The push delivery vendor, e.g., Google, Mozilla, Microsoft                                           | Push                         |
| Browser Details               | The browser name, version, type (desktop/mobile), and user agent                                    | Analytics                    |
| App version                   | The app's version, when provided by the integration                                                 | Analytics, In-App Automation |
| Session                       | Browsing session and associated attribution data                                                    | Analytics                    |
| Notification events           | Push notification interaction events                                                                | Analytics, Push              |
| In-App Automation events      | Events within an In-App display: displays, resolutions, page views, button taps, and survey results | Analytics, In-App Automation |

### Website Data Collection

In addition to the data automatically collected by the SDK, the website
integration can provide data to the SDK for collection: 

| Data                        | Description                                                                        | Privacy Manager Features      |
|-----------------------------|------------------------------------------------------------------------------------|-------------------------------|
| Channel Tags                | Tags and tag groups set on the channel                                             | Tags and Attributes           |
| Channel Subscription Lists  | Subscription Lists set on the channel                                              | Tags and Attributes           |
| Channel Attributes          | Attributes set on the channel                                                      | Tags and Attributes           |
| Contact Tags                | Tags and tag groups set on the contact                                             | Tags and Attributes, Contacts |
| Contact Subscription Lists  | Subscription Lists set on the contact                                              | Tags and Attributes, Contacts |
| Contact Attributes          | Attributes set on the contact                                                      | Tags and Attributes, Contacts |
| Named User                  | Contact's external ID                                                              | Contacts                      |
| Associated Channels         | Email and email opt-in data, SMS and SMS opt-in data, etc.                         | Contacts                      |
| Associated Identifiers      | Additional analytics identifiers                                                   | Analytics                     |
| Custom Events               | Website's custom events                                                            | Analytics                     |
| Screen Tracking             | Website's screen tracking                                                          | Analytics                     |
| Permission Collection       | Additional permissions collected by the SDK                                        | Analytics                     |
| Feature Flag Interaction    | Events related to [Feature Flags](https://www.airship.com/docs/reference/glossary/#feature_flag) | Feature Flags, Analytics      |

## When we collect data

The Airship SDK will not send any data to the Airship platform until a channel
is created, which occurs using one of the following methods:

* Creating a channel through [sdk.create](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/UaSDK.html#create)

* Registering for push notifications through [sdk.register](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/UaSDK.html#create)

* Registering an email, sms, or open channel through the [Contact](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/UaSDK.Contact.html)
 interface
* Associating an exiting channel through the [Contact](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/UaSDK.Contact.html)
 interface
* Using a [plugin](https://www.airship.com/docs/developer/sdk-integration/web/plugins/) for performing
  registration of a channel or associated channel

Prior to those actions, the SDK may store data within the browser, in accordance
with enabled Privacy Manager flags, should you perform specific actions like
setting tags or attributes on a channel or contact. However, the values will not be
sent to Airship until a channel is created.

> **Important:** Performing any action that results in data collection will count the browser
> profile as a [Monthly Unique Visitor](https://www.airship.com/docs/reference/billing/#monthly-unique-visitors) for that month, and any
> subsequent visits from that browser profile will count in the month the visit
> occurred.


## Using Privacy Manager

The [Privacy Manager](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/PrivacyManager.html)
 allows
setting default enabled features as well as modifying the enabled features at
runtime. This table provides a mapping of the flags:

| Privacy Manager Flag | String Value          |
|----------------------|-----------------------|
| Push                 | `push`                |
| In-App Automation    | `in_app_automation`   |
| Tags and Attributes  | `tags_and_attributes` |
| Contacts             | `contacts`            |
| Feature Flags        | `feature_flags`       |
| Analytics            | `analytics`           |
| All                  | `all`                 |

### Configuring Default Enabled Features

To configure the default set of enabled features, you must pass an array of
`enabledFeatures` in the configuration options in both your snippet _and_
service worker's initialization of the Airship SDK:

**Configuring Enabled Features**

```js
...
  'UA', {
    vapidPublicKey: 'vapidPublicKey',
    appKey: 'appKey',
    token: 'token',
    enabledFeatures: [
      'push',
      'in_app_automation',
      'tags_and_attributes'
    ]
  });
```


When not provided, all features will be enabled. Passing a list of
`enabledFeatures` only specifies the defaults. You may enable additional
features at runtime.

### Modifying Enabled Features

Features can be enabled or disabled using the `[PrivacyManager](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/PrivacyManager.html)
` interface:

**Enabling Features**

```js
const sdk = await UA
await sdk.privacyManager.enable('push', 'in_app_automation')
```


**Disabling Features**

```js
const sdk = await UA
await sdk.privacyManager.disable('push', 'in_app_automation')
```


### Disabled Feature Errors

When attempting to use a feature that is disabled, the SDK will raise errors
that detail why the feature could not be used. If you plan to call these APIs
when the Privacy Manager-enabled features could be in different states, you must
catch these errors if you wish for your code to continue:

**Handling Disabled Features**

```js
const sdk = await UA

try {
  await sdk.channel.editTags()
    .add("device", "cool_tag")
    .apply()
} catch (e) {
  // handle error as desired
}
```


## Legacy SDK Data Collection Flags

Before the Privacy Manager was implemented for the Airship SDK, there were two
exposed controls for data collection. These controls have been mapped to the
Privacy Manager, retaining their previous behavior. The flags and APIs discussed
below are deprecated and will be removed in the next major version.

### Configuration

The following configuration values remain available, and are mapped to the
Privacy Manager as follows:

* `disableAnalytics` disables the _Analytics_ Privacy Manager flag and
  disallows it being enabled through the Privacy Manager.
* `dataCollectionOptInEnabled` disables _all_ Privacy Manager flags by default
  and persists that value to the browser upon visit. Individual features may be
  enabled or disabled through the Privacy Manager.

> **Important:** It is considered an error to specify `enabledFeatures` and
> `dataCollectionOptInEnabled` simultaneously. Doing so prevents the Airship
> SDK from initializing.


### Runtime

At runtime, we supported disabling data collection and analytics via calls to
the Airship SDK. We recommended using the Privacy Manager, and the following
describes how they are mapped.

#### Analytics

Calls to [sdk.analytics.setEnabled](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/AnalyticsManager.html#setEnabled)
 enable or disable the `analytics`
Privacy Manager feature depending on the value passed to the method.

**Disabling Analytics**

```js
const sdk = await UA

// legacy call to disable analytics
await sdk.analytics.setEnabled(false)
// equivalent privacy manager call
await sdk.privacyManager.disable('analytics')
```


**Enabling Analytics**

```js
const sdk = await UA

// legacy call to enable analytics
await sdk.analytics.setEnabled(true)
// equivalent privacy manager call
await sdk.privacyManager.enable('analytics')
```


#### Data Collection

Calls to [sdk.setDataCollectionEnabled](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/UaSDK.html#setDataCollectionEnabled)
 enable or disable **all** Privacy
Manager features depending on the value passed to the method.

**Disabling Data Collection**

```js
const sdk = await UA

// legacy call to disable data collection
await sdk.setDataCollectionEnabled(false)
// equivalent privacy manager call
await sdk.privacyManager.disable('all')
```


**Enabling Data Collection**

```js
const sdk = await UA

// legacy call to enable data collection
await sdk.setDataCollectionEnabled(true)
// equivalent privacy manager call
await sdk.privacyManager.enable('all')
```

