# Google Analytics

Source: https://ceyo.ai/docs/signal/google-analytics-guides

### Google Analytics guides

Connect GA4 and start reading traffic and conversion data.

### Connect with Google OAuth

Use a key with `analytics:write`. Start authorization, send the user to the returned URL, let Signal's public callback finish the exchange, then list accounts and properties and select a property.

```curl
curl --request POST \
  --url 'https://api.signal.ceyo.ai/v1/projects/{project_id}/analytics/connect' \
  --header "Authorization: Bearer ${SIGNAL_API_KEY}"
```

> **Required package setting**
>
> The scope's package must enable `advanced.google_analytics_enabled`.

### Use an external token source

Create a workspace token source when your platform manages Google access tokens. Attach it to a project or location with your external resource ID and GA4 property ID, then trigger a sync.

```curl
curl --request PUT \
  --url 'https://api.signal.ceyo.ai/v1/projects/{project_id}/analytics/external_source' \
  --header "Authorization: Bearer ${SIGNAL_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{"token_source_id":"{token_source_id}","external_resource_id":"customer-123","property_id":"properties/123456"}'
```

### Fetch analytics data

Use `analytics:read` to fetch the overview, referrals, conversions, conversion events, or landing pages. The same endpoints work for locations by inserting `/locations/{location_id}` before `/analytics`.

```curl
curl --request GET \
  --url 'https://api.signal.ceyo.ai/v1/projects/{project_id}/analytics?days=30' \
  --header "Authorization: Bearer ${SIGNAL_API_KEY}"
```

> **Sync is asynchronous**
>
> A sync request returns `202`. Poll the connection until `syncing_since` is null and `last_synced_at` changes.
