> For the complete documentation index, see [llms.txt](https://docs.uibakery.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uibakery.io/on-premise/on-premise-features/external-analytics.md).

# External analytics

{% hint style="success" %}
This feature is available only on *Enterprise* self-hosted and *Enterprise* cloud-hosted plans.
{% endhint %}

The external analytics feature allows you to forward analytics and audit logs events with third-party analytics/logging solutions. If settings for external analytics are provided, a third-party script will be dynamically loaded, and Audit Log events will be forwarded to the respective third-party system. NOTE: default Audit logs will still be available in your UI Bakery workspace.

Currently, integrations with the following third-party analytics/logging systems are available:

* Datadog
* Google Analytics 4
* Google Tag Manager

{% hint style="info" %}
External analytics scripts are only loaded after the user is logged into the platform and for anonymous apps. No external analytics scripts are loaded for the UI Bakery login screen.
{% endhint %}

## Datadog external analytics

Currently, UI Bakery provides the interface to set up integration with the following Datadog services:

* [Real user monitoring](https://docs.datadoghq.com/real_user_monitoring/)
* [Browser logs](https://docs.datadoghq.com/logs/log_collection/javascript/)

It is also possible to set up UI Bakery backend log collection using [the Datadog agent](https://docs.datadoghq.com/agent/) but this has to be done on the VM or Kubernetes level.

### Setting up Datadog Real User Monitoring (RUM)

Datadog RUM allows recording user sessions to better understand their user experience and track issues in app business logic.

In your Datadog console, navigate to UX monitoring > RUM applications and click the "New application" button:

<figure><img src="/files/bK4xY8QFe8AK5vwofofu" alt=""><figcaption></figcaption></figure>

Choose JS as your application type. Type your application name, for instance, "UI Bakery", and click "Create new application" button. You will be provided with the initialization script similar to:

```javascript
import { datadogRum } from '@datadog/browser-rum';

datadogRum.init({
    applicationId: 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    clientToken: 'pubxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    site: 'datadoghq.com',
    service:'ui-bakery',
    
    // Specify a version number to identify the deployed version of your application in Datadog 
    // version: '1.0.0',
    sessionSampleRate: 100,
    sessionReplaySampleRate: 20,
    trackUserInteractions: true,
    trackResources: true,
    trackLongTasks: true,
    defaultPrivacyLevel:'mask-user-input'
});
    
datadogRum.startSessionReplayRecording();
```

Take the object from init function and convert it to valid JSON (replace the single quotes and add double quotes to properties name:

```json
{
    "applicationId": "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "clientToken": "pubxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "site": "datadoghq.com",
    "service":"ui-bakery",
    "sessionSampleRate": 100,
    "sessionReplaySampleRate": 20,
    "trackUserInteractions": true,
    "trackResources": true,
    "trackLongTasks": true,
    "defaultPrivacyLevel": "mask-user-input"
}
```

Paste the JSON object to your Datadog RUM settings in UI Bakery:

<figure><img src="/files/mRqElOs7IotIu2MbrlyR" alt=""><figcaption></figcaption></figure>

Click Save and reload your pages for changes to apply.

### Setting up Datadog browser logs

Datadog browser logs allow streaming UI Bakery audit logs directly to Datadog to help you analyze them in a single place.

In order to set this feature up, first you need to acquire your client token as described [here](https://docs.datadoghq.com/account_management/api-app-keys/#client-tokens). The client token usually has a format of `pubxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`.

After this is done, paste the following JSON to your Datadog browser logs settings replacing `<DATADOG_CLIENT_TOKEN>` with a valid client token:

```json
{
    "clientToken": "<DATADOG_CLIENT_TOKEN>",
    "site": "datadoghq.com",
    "forwardErrorsToLogs": true,
    "sessionSampleRate": 100
}
```

<figure><img src="/files/oqL6CXnaGJHPktKl5xZn" alt=""><figcaption></figcaption></figure>

After reloading the page, the Datadog client script will start collecting your Audit Logs and store them in UI Bakery.

## Setting up Google analytics 4 or GTM

In order to set up Google Analytics 4 or GTM you will need to acquire your tracking ID and paste it into the respective settings field.

<figure><img src="/files/gDIbKgEJyJayN1EGTVdw" alt=""><figcaption></figcaption></figure>

After this is done and the page is reloaded, this Google Analytics or GTM script will be loaded and UI Bakery Audit logs would be streamed to Google Analytics 4 as events, or in GTM as dataLayer events.

## Global external analytics script

UI Bakery also allows adding script tags on the instance level using `UI_BAKERY_GTM` an environment variable. It will add the provided string after the opening `<body>` tag.

{% hint style="info" %}
Please note, if you use this option, UI Bakery will not stream audit log events to the external analytics you installed with the script.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.uibakery.io/on-premise/on-premise-features/external-analytics.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
