# Connect Google Analytics to StoreScope Analytics

> Website sessions, users, page views, key events and traffic channels for each app's site.

## What it unlocks in StoreScope Analytics

- Website sessions, users, new users, page views, key events and traffic channels for each app's site.

## The access it needs

| For | Least role or permission |
|---|---|
| Reading reports | Viewer, on each property (Admin, Property access management) |

- Both the Google Analytics Admin API (to find each site's property) and the Data API (to read it) must be enabled on the key's project.

## Steps

1. Use a Google service account JSON key (the Search Console one works). Enable the Google Analytics Admin API and Data API on its project. [Enable the Data API](https://console.cloud.google.com/apis/library/analyticsdata.googleapis.com)
2. In Google Analytics, Admin, Property access management, add the service account's email as a Viewer on each property. [Open Google Analytics](https://analytics.google.com/analytics/web/)
3. Set each app's website on the Apps page. Each app gets the property whose web stream serves that site, found by itself.
4. In StoreScope Analytics, open Connections, choose Google Analytics, fill in the form and save. The connection is checked live with the store first; a connection that fails the check is never saved.

## What the form asks for

- Service account JSON key (optional)
- Or paste the JSON (optional)

## Errors the check can show

The exact sentence the Connections page shows (<angle brackets> are your own values), then what to do.

- "The service account JSON is required."
  Upload the JSON key file you downloaded from Google Cloud, or paste its contents.
- "the uploaded JSON: not valid JSON"
  The file is not the key file, or the paste was cut short. Download the key again (Google Cloud, IAM and Admin, Service accounts, the account, Keys, Add key, JSON).
- "service account JSON is missing client_email/private_key"
  This is not a service account key file (an OAuth client file looks similar). Create a JSON key for the service account.
- "Upload a service account key ("type": "service_account"), not a user credential."
  A personal sign-in file was uploaded. Only a service account key is accepted.
- "The key works but sees no property: add <service account e-mail> as a Viewer in Google Analytics."
  Add that e-mail as a Viewer on each property, then connect again.
- "Enable the Google Analytics Admin API and Data API on the service account's Google Cloud project, then try again."
  Enable both APIs on the project the key belongs to.
- "Google Analytics answered <status>."
  Google answered something unexpected. Try again in a few minutes.

Errors any connection can show: https://storescope.devino.ca/docs/connect.md
