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

# Connecting Google Analytics to your app

> Show traffic, engagement, and campaign data from Google Analytics in your app's dashboards and reports, using one shared account or each person's own account.

Connect your app to Google Analytics to show traffic trends, engagement, and campaign results in dashboards and reports. Use one shared Google account for your whole app or let each person connect their own.

***

## What you can do

Bring your Google Analytics data into your app.

> [card] Show traffic trends
>
> Show visits, top pages, and traffic sources over time in a dashboard inside your app.

> [card] Analyze user behavior
>
> Look at engagement and conversion funnels to see where visitors drop off.

> [card] Build regular reports
>
> Generate weekly reports with traffic and engagement data for your team.

> [card] Track campaigns
>
> Compare how your marketing campaigns perform using your Analytics data.

**Example prompts**

In the AI chat, describe the property, the metrics to show, and the date range. For example:

```text wrap theme={null}
Show my website traffic trends and top-performing pages.
```

```text wrap theme={null}
Create a dashboard displaying key analytics metrics.
```

```text wrap theme={null}
Analyze user behavior and conversion funnels from Analytics.
```

```text wrap theme={null}
Generate weekly reports with traffic and engagement data.
```

```text wrap theme={null}
Track marketing campaign performance using Analytics data.
```

***

## Connecting Google Analytics

Choose how people connect: one shared account for your whole app, or each person's own account.

> [tab] Shared connector
>
> Connect one Google account, and everyone who uses your app shares it and its Analytics data.
>
> **To add a shared Google Analytics connector:**
>
> 1. Click **Connectors** in your workspace sidebar.
>
> 2. Click **Add connector**.
>
> 3. Search for **Google Analytics** and click it.
>
> 4. Select **Shared connector**, then click **Next**.
>
> 5. Enter a **Connection name**.
>
> 6. In **Who can access**, choose **Apps and Super agent**, **Apps only**, or **Super agent only**. **Apps and Super agent** is selected by default.
>
> 7. Choose the [scopes](#scopes-and-permissions) your app needs under **Permissions**:
>
>    * **Read-only:** Your app can view your Analytics data and settings. This is the default.
>    * **Read & write:** Your app can also change your Analytics account and property settings.
>    * **Custom:** Select the optional permissions your app needs. Required permissions stay selected.
>
>    ![Shared Google Analytics connector setup with Connection name, Who can access, and Read-only permissions selected](https://mintcdn.com/base44/f-7NhkNoXDoVi_Da/images/apps-connectors-google-analytics-shared-setup.png?fit=max\&auto=format\&n=f-7NhkNoXDoVi_Da\&q=85\&s=cd95db20bce0213e7874e1cb16c1eb6b)
>
>    Setting up a shared Google Analytics connector
>
> 8. Click **Add connector**.
>
> 9. Sign in with the Google account that has access to your Analytics properties.

> [tab] App user connector
>
> Each person connects their own Google account, so your app can show the Analytics properties they can access.
>
> > [!WARNING]
> >
> > Only workspace owners and admins can set this up.
>
> > [!TIP]
> >
> > **Before you set up an app user connector:** You need a Google Cloud OAuth client with its Client ID and Client Secret. In the same Google Cloud project, turn on the Google Analytics Data API, and the Google Analytics Admin API if your app lists properties or changes settings. See [Using your own OAuth client](https://docs.base44.com/Integrations/Connectors.md#using-your-own-oauth-client).
>
> **To add an app user Google Analytics connector:**
>
> 1. Click **Connectors** in your workspace sidebar.
>
> 2. Click **Add connector**.
>
> 3. Search for **Google Analytics** and click it.
>
> 4. Select **App user connector**, then click **Next**.
>
> 5. Copy the **Callback URL**.
>
> 6. In your Google Cloud OAuth client, add the Callback URL to the authorized redirect URIs.
>
> 7. Back in the **Add Google Analytics Connection** form, enter a **Connector name**.
>
> 8. Enter your **Client ID**.
>
> 9. Enter your **Client Secret**.
>
> 10. Select the [scopes](#scopes-and-permissions) your app needs under **Scopes**.
>
>     ![Google Analytics Scopes list with email locked, and analytics readonly and analytics edit to choose from](https://mintcdn.com/base44/f-7NhkNoXDoVi_Da/images/apps-connectors-google-analytics-app-user-scopes.png?fit=max\&auto=format\&n=f-7NhkNoXDoVi_Da\&q=85\&s=7610bcb079782883d45daf160a69f252)
>
>     Choosing scopes for an app user connector
>
> 11. Click **Add Connector**.
>
> 12. Go to your app editor.
>
> 13. Ask the AI chat to add a way for people to connect their own Google Analytics account.

***

## Scopes and permissions

Scopes control what your app can do in Google Analytics. You choose them when you set up a connector.

> [card]
>
> **1. Base44 adds**
>
> Base44 always includes this scope. You see it locked under **Custom** for a shared connector, or under **Scopes** for an app user connector.
>
> * `email`: Identify the Google account that connects
>
> **2. You configure**
>
> Choose a permission option for a shared connector, or select scopes for an app user connector. Google Analytics scope names start with `https://www.googleapis.com/auth/`:
>
> * `analytics.readonly`: View your Analytics data and settings
> * `analytics.edit`: Edit your Analytics account and property settings
>
> **Access:** Your app sees the Analytics accounts and properties the connected Google account can access.

***

## Using backend functions

Once Google Analytics is connected, your backend functions can retrieve an access token and call the Google Analytics Data API directly. Base44 handles sign-in and keeps the token up to date for you.

* For a shared connection, use `getConnection()` to retrieve the token.
* For an app user connection, use `getCurrentAppUserConnection()` so each request uses the signed-in person's token.

Call the Google Analytics Data API at `analyticsdata.googleapis.com` and pass the token in the `Authorization` header:

```javascript theme={null}
// Shared connection: one account the whole app uses
const { accessToken } = await base44.asServiceRole.connectors.getConnection("google_analytics");

const propertyId = "123456789"; // Your Google Analytics property ID

const response = await fetch(
  `https://analyticsdata.googleapis.com/v1beta/properties/${propertyId}:runReport`,
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${accessToken}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
      dimensions: [{ name: "pagePath" }],
      metrics: [{ name: "screenPageViews" }],
    }),
  },
);
const report = await response.json();
```

> [card] [Shared connectors](https://docs.base44.com/developers/backend/resources/connectors/shared-connectors.md)
>
> Configure, deploy, and call a shared connection from a backend function.

> [card] [App user connectors](https://docs.base44.com/developers/backend/resources/connectors/app-user-connectors.md)
>
> Retrieve a per-user token and call the API as the signed-in person.

***

## Troubleshooting

Check the connection, the Google account, and its scopes if Google Analytics stops working in your app.

> [accordion] The connection needs to be reconnected
>
> If Google Analytics access is lost or expires, the connection shows a **Reconnect this connection** section. For a shared connector, [reconnect it](https://docs.base44.com/Integrations/Connectors.md#managing-your-connectors) and sign in with the same Google account. Every app that uses it works again. For an app user connector, each person reconnects their own account from inside your app.

> [accordion] My Analytics data isn't showing up
>
> Check that the Google account you connected has access to the property you want, and that your app uses that property's ID. A new property can take a while to collect data, so compare the same date range in Google Analytics.

> [accordion] My app can't change Analytics settings
>
> Your app needs the `analytics.edit` scope to change account and property settings.
>
> * For a shared connector, permissions are set when you add the connection. Click **Add another connector** on the Google Analytics connector page and choose **Read & write** for the new connection.
> * For an app user connector, open it on the Google Analytics connector page, add `analytics.edit` to its scopes, and click **Save Changes**. People who already connected keep their earlier access until they connect again.

> [accordion] Some people can't connect their own Google account
>
> Your OAuth client starts in testing mode, where only approved test users can connect. Before opening access more broadly, move your OAuth app to production and complete any verification Google requires.

> [accordion] Connecting fails with a redirect URI error
>
> Copy the **Callback URL** from the **Add Google Analytics Connection** form and add it exactly to the authorized redirect URIs in your Google Cloud OAuth client.

***

## FAQs

> [accordion] Which Google Analytics role does the account need?
>
> Connect a Google account with at least the Viewer role on the properties you want to show. To let your app change account or property settings, the account needs the Editor role.

> [accordion] Can my app use more than one property?
>
> Yes. If the connected Google account has access to several properties, name the one you want in the AI chat, or ask for a way to switch between them.

> [accordion] Can I use Google Analytics and Google Search Console together?
>
> Yes. Add each connector separately, then ask the AI chat to combine traffic from Google Analytics with search performance from [Google Search Console](https://docs.base44.com/Integrations/google-search-console-connector.md) in one dashboard.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.