# Google Analytics Integration via LowCodeAPI
## Overview
Google Analytics API provides programmatic access to your analytics data. Build custom dashboards, automate reporting, and integrate analytics insights into your applications with 20+ available endpoints.
## Base Endpoint
```
https://api.lowcodeapi.com/googleanalytics/
```
## Authentication
LowCodeAPI handles authentication automatically. You only need to:
1. **Sign up** at [Google Cloud Console](https://console.cloud.google.com/apis/credentials)
2. **Create OAuth2.0 credentials** for Google Analytics
3. **Configure scopes** for analytics access
4. **Connect your account** in LowCodeAPI dashboard
5. **Use your `api_token`** in all requests
The `api_token` is your LowCodeAPI authentication token. LowCodeAPI will automatically:
- Fetch your Google Analytics OAuth credentials from the database
- Handle OAuth flow and token refresh
- Apply authentication to each request
**Auth Type**: OAuth2.0
**Available Scopes**:
- `https://www.googleapis.com/auth/analytics.readonly` - View analytics data
- `https://www.googleapis.com/auth/analytics` - View and manage analytics data
## API Categories
- **Google Other** - Google service integrations
## Common Endpoints
### Category: Regular API
#### Get Analytics Reports
**Method**: `POST` | **LowCodeAPI Path**: `/v4/reports:batchGet`
**Full URL**:
```
https://api.lowcodeapi.com/googleanalytics/v4/reports:batchGet?api_token={api_token}
```
**Description**: Returns analytics data for a view (profile)
**Query Parameters**:
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_token` | string | Yes | Your LowCodeAPI authentication token |
**Body Parameters**:
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `reportRequests` | array | Yes | Requests, each request will have a separate response |
| `reportRequests[].viewId` | string | Yes | The Analytics view ID |
| `reportRequests[].dateRanges` | array | Yes | Date ranges for the report |
| `reportRequests[].metrics` | array | Yes | Metrics to retrieve |
| `reportRequests[].dimensions` | array | No | Dimensions to group by |
**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/googleanalytics/v4/reports:batchGet?api_token=YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"reportRequests": [
{
"viewId": "123456789",
"dateRanges": [
{
"startDate": "30daysAgo",
"endDate": "today"
}
],
"metrics": [
{"expression": "ga:sessions"},
{"expression": "ga:pageviews"}
],
"dimensions": [
{"name": "ga:date"}
]
}
]
}'
```
**Example Response**:
```json
{
"data": {
"reports": [
{
"columnHeader": {
"dimensions": ["ga:date"],
"metricHeader": {
"metricHeaderEntries": [
{"name": "ga:sessions"},
{"name": "ga:pageviews"}
]
}
},
"data": {
"rows": [
{
"dimensions": ["20240101"],
"metrics": [
{"values": ["1000", "5000"]}
]
}
]
}
}
]
}
}
```
**Official Documentation**: [https://developers.google.com/analytics/devguides/reporting/core/v4](https://developers.google.com/analytics/devguides/reporting/core/v4)
---
## Usage Examples
### Example 1: Basic Traffic Report
This example demonstrates getting basic website traffic data:
```bash
# Get sessions and pageviews for the last 30 days
# Replace VIEW_ID with your Google Analytics View ID (e.g., 123456789)
curl -X POST "https://api.lowcodeapi.com/googleanalytics/v4/reports:batchGet?api_token=YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"reportRequests": [
{
"viewId": "VIEW_ID",
"dateRanges": [
{
"startDate": "30daysAgo",
"endDate": "today"
}
],
"metrics": [
{"expression": "ga:sessions"},
{"expression": "ga:users"},
{"expression": "ga:pageviews"},
{"expression": "ga:bounceRate"}
]
}
]
}'
```
### Example 2: Traffic by Source
```bash
# Get traffic breakdown by source/medium
# Replace VIEW_ID with your actual View ID
curl -X POST "https://api.lowcodeapi.com/googleanalytics/v4/reports:batchGet?api_token=YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"reportRequests": [
{
"viewId": "VIEW_ID",
"dateRanges": [
{"startDate": "7daysAgo", "endDate": "today"}
],
"dimensions": [
{"name": "ga:source"},
{"name": "ga:medium"}
],
"metrics": [
{"expression": "ga:sessions"},
{"expression": "ga:pageviews"}
],
"orderBys": [
{"fieldName": "ga:sessions", "sortOrder": "DESCENDING"}
],
"pageSize": 20
}
]
}'
```
### Example 3: Multiple Reports in One Request
```bash
# Batch multiple report requests in a single API call
# Replace VIEW_ID with your actual View ID
curl -X POST "https://api.lowcodeapi.com/googleanalytics/v4/reports:batchGet?api_token=YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"reportRequests": [
{
"viewId": "VIEW_ID",
"dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}],
"metrics": [{"expression": "ga:sessions"}],
"dimensions": [{"name": "ga:date"}]
},
{
"viewId": "VIEW_ID",
"dateRanges": [{"startDate": "30daysAgo", "endDate": "today"}],
"metrics": [{"expression": "ga:pageviews"}],
"dimensions": [{"name": "ga:pagePath"}],
"orderBys": [{"fieldName": "ga:pageviews", "sortOrder": "DESCENDING"}],
"pageSize": 10
}
]
}'
```
## Complete Endpoint Reference
For a complete list of all endpoints and their parameters, refer to:
- **OpenAPI Definition**: `https://backend.lowcodeapi.com/googleanalytics/definition`
- **Official Provider Documentation**: [https://developers.google.com/analytics/devguides/reporting/core/v4](https://developers.google.com/analytics/devguides/reporting/core/v4)
## Rate Limits & Best Practices
- **Rate limits**: Based on Google Cloud project quota
- **Best practice**: Use batch requests for multiple reports
- **Best practice**: Cache results for frequently accessed data
- **Best practice**: Use date ranges to limit data volume
- **Best practice**: Use pagination for large result sets
## Error Handling
Standard HTTP status codes apply