# Analytics and Reporting for the Web SDK

The Airship SDK provides analytics and reporting support.

Our Web SDK comes with analytics support out of the box, and by default, there
are no explicit preferences you need to set in order to enable reporting. The
integration is handled automatically unless you set [setDataCollectionEnabled](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/UaSDK.html#setDataCollectionEnabled)
 to
`true`.

## Custom Events

[Custom Events](https://www.airship.com/docs/reference/glossary/#custom_event) are available out of the box and ship with the Web SDK.
See the events in our [Airship Web SDK Reference](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/index.html)
 for complete details.

Custom Events require Analytics to be enabled, which is the default setting. If you
disable analytics, no Custom Events will be recorded.

### Templates

Custom Event Templates are a wrapper for Custom Events and are available for Web, [iOS](https://www.airship.com/docs/developer/sdk-integration/apple/analytics/#templates), and [Android](https://www.airship.com/docs/developer/sdk-integration/android/analytics/#templates). See also the [Airship Web SDK Reference](https://www.airship.com/docs/reference/libraries/web-notify-sdk/v2-latest/index.html)
.

#### Account

Use this template to create Custom Events for account-related events. The template is written with account registration as the example.


#### Javascript



Track a registered account event:

```js
new sdk.CustomEvent.templates.account.RegisterEvent().track()
```


With optional properties:

```js
new sdk.CustomEvent.templates.account.RegisterEvent(9.99, {
  category: "premium",
}, "12345").track()
```




#### Media

Use this template to create Custom Events for media-related events, including consuming, browsing, starring, and sharing content.


#### Javascript



Track a consumed content event:

```js
new sdk.CustomEvent.templates.media.ConsumedContentEvent().track()
```


With an optional value:

```js
new sdk.CustomEvent.templates.media.ConsumedContentEvent(1.99).track()
```


With optional properties:

```js
new sdk.CustomEvent.templates.media.ConsumedContentEvent(2.99, {
  category: "entertainment",
  identifier: "12322",
  description: "Watching latest entertainment news.",
  type: "video",
  author: "UA Enterprises",
  feature: true,
  published_date: "2017-10-13T17:47:09",
}).track()
```





#### Javascript



Track a starred content event:

```js
new sdk.CustomEvent.templates.media.StarredContentEvent().track()
```


With optional properties:

```js
new sdk.CustomEvent.templates.media.StarredContentEvent(null, {
  category: "entertainment",
  identifier: "12322",
  description: "Watching latest entertainment news.",
  type: "video",
  author: "UA Enterprises",
  feature: true,
  published_date: "2017-10-13T17:47:09",
}).track()
```






#### Javascript



Track a browsed content event:

```js
new sdk.CustomEvent.templates.media.BrowsedContentEvent().track()
```


With optional properties:

```js
new sdk.CustomEvent.templates.media.BrowsedContentEvent(null, {
  category: "entertainment",
  identifier: "12322",
  description: "Watching latest entertainment news.",
  type: "video",
  author: "UA Enterprises",
  feature: true,
  published_date: "2017-10-13T17:47:09",
}).track()
```





#### Javascript



Track a shared content event with a source and medium:

```js
new sdk.CustomEvent.templates.media.SharedContentEvent("facebook", "social").track()
```


With optional properties:

```js
new sdk.CustomEvent.templates.media.SharedContentEvent("facebook", "social", {
  category: "entertainment",
  identifier: "12322",
  description: "Watching latest entertainment news.",
  type: "video",
  author: "UA Enterprises",
  feature: true,
  published_date: "2017-10-13T17:47:09",
}).track()
```




#### Retail

Use this template to create Custom Events for retail-related events, including browsing a product, adding an item to a cart, purchasing an item, starring a product, and sharing a product.



#### Javascript



Track a purchased event:

```js
new sdk.CustomEvent.templates.retail.PurchasedEvent().track()
```


With optional properties:

```js
new sdk.CustomEvent.templates.retail.PurchasedEvent(99.99, {
  id: "12345",
  category: "mens shoes",
  description: "Low top",
  brand: "SpecialBrand",
  new_item: true,
}, "13579").track()
```






#### Javascript



Track a browsed event:

```js
new sdk.CustomEvent.templates.retail.BrowsedEvent().track()
```


With optional properties:

```js
new sdk.CustomEvent.templates.retail.BrowsedEvent(99.99, {
  id: "12345",
  category: "mens shoes",
  description: "Low top",
  brand: "SpecialBrand",
  new_item: true,
}, "13579").track()
```






#### Javascript



Track an added-to-cart event:

```js
new sdk.CustomEvent.templates.retail.AddedToCartEvent().track()
```


With optional properties:

```js
new sdk.CustomEvent.templates.retail.AddedToCartEvent(99.99, {
  id: "12345",
  category: "mens shoes",
  description: "Low top",
  brand: "SpecialBrand",
  new_item: true,
}, "13579").track()
```





#### Javascript



Track a starred product event:

```js
new sdk.CustomEvent.templates.retail.StarredProductEvent().track()
```


With optional properties:

```js
new sdk.CustomEvent.templates.retail.StarredProductEvent(99.99, {
  id: "12345",
  category: "mens shoes",
  description: "Low top",
  brand: "SpecialBrand",
  new_item: true,
}, "13579").track()
```





#### Javascript



Track a shared product event with a source and medium:

```js
new sdk.CustomEvent.templates.retail.SharedProductEvent("facebook", "social").track()
```


With optional properties:

```js
var event = new sdk.CustomEvent.templates.retail.SharedProductEvent("facebook", "social", {
  id: "12345",
  category: "mens shoes",
  description: "Low top",
  brand: "SpecialBrand",
  new_item: true,
})
event.value = 99.99
event.transactionId = "13579"
event.track()
```




## Screen Tracking

The Airship SDK gives you the ability to track which screens a user views within
the application, how long a user stayed on each screen, and also includes the user's previous screen.
These events then come through [Real-Time Data Streaming](https://www.airship.com/docs/reference/glossary/#rtds), allowing you
to see the path a user took through your website or application, or trigger actions based
on a user visiting a particular screen.

**Tracking a Screen View**


```js
const sdk = await UA
await sdk.analytics.trackScreen("MainScreen")
```



## Disable Analytics

When the website has disabled analytics in the SDK at the website level or for an
individual user, no analytics events will be sent to Airship. Analytics events
includes things like sessions, clicks, and custom events.

**To disable analytics for a specific browser/user**


```js
const sdk = await UA
await sdk.analytics.setEnabled(false)
```



If it is necessary to disable analytics for an entire install set
`disableAnalytics` to `true` in both the snippet and push-worker configuration.

**Disable all analytics**


```js
disableAnalytics: true
```


## Custom Identifiers

A custom identifier associates an external identifier with a [Channel ID](https://www.airship.com/docs/reference/glossary/#channel_id). They are visible in [Real-Time Data Streaming](https://www.airship.com/docs/reference/glossary/#rtds). We recommend adding
any IDs that you may want to be visible in your event stream. You can assign up to 20 custom identifiers to
a device. Unlike other identifiers (e.g., tags), you cannot use custom identifiers to target your users.

**Set a custom identifier**


```js
const sdk = await UA
const editor = sdk.analytics.associatedIdentifiers.edit()
await editor
  .add("THIRD_PARTY_ANALYTICS", "my-analytics-id-123")
  .apply()
```

