Skip to content

Commit 613a9dc

Browse files
docs: add google analytics documentation
1 parent 7d207de commit 613a9dc

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

.github/workflows/publish-mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ on:
33
push:
44
branches:
55
- main
6+
paths:
7+
- 'docs/**.md'
68
permissions:
79
contents: write
810
jobs:
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# garf for Google Analytics Data API
2+
3+
[![PyPI](https://img.shields.io/pypi/v/garf-google-analytics?logo=pypi&logoColor=white&style=flat-square)](https://pypi.org/project/garf-google-analytics)
4+
[![Downloads PyPI](https://img.shields.io/pypi/dw/garf-google-analytics?logo=pypi)](https://pypi.org/project/garf-google-analytics/)
5+
6+
Interacts with [Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1/rest).
7+
8+
## Install
9+
10+
Install `garf-google-analytics` library
11+
12+
/// tab | pip
13+
```
14+
pip install garf-executors garf-google-analytics
15+
```
16+
///
17+
18+
/// tab | uv
19+
```
20+
uv add garf-executors garf-google-analytics
21+
```
22+
///
23+
24+
## Usage
25+
26+
### Prerequisites
27+
28+
* [Google Analytics API](https://console.cloud.google.com/apis/library/analytics.googleapis.com) enabled.
29+
30+
31+
/// tab | cli
32+
```bash
33+
echo "
34+
SELECT
35+
dimension.country AS country,
36+
metric.activeUsers AS active_users
37+
FROM resource
38+
WHERE
39+
start_date >= '2025-09-01'
40+
AND end_date <= '2025-09-07'
41+
" > query.sql
42+
garf query.sql --source google-analytics \
43+
--output csv \
44+
--source.property-id=GA_PROPERTY_ID
45+
```
46+
///
47+
48+
/// tab | python
49+
50+
```python
51+
from garf_io import writer
52+
from garf_google_analytics import GoogleAnalyticsApiReportFetcher
53+
54+
query = """
55+
SELECT
56+
dimension.country AS country,
57+
metric.activeUsers AS active_users
58+
FROM resource
59+
WHERE
60+
start_date >= '2025-09-01'
61+
AND end_date <= '2025-09-07'
62+
"""
63+
64+
fetched_report = (
65+
GoogleAnalyticsApiReportFetcher()
66+
.fetch(query, property_id='PROPERTY_ID')
67+
)
68+
69+
csv_writer = writer.create_writer('csv')
70+
csv_writer.write(fetched_report, 'query')
71+
```
72+
///

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ nav:
7575
- Data API: fetchers/youtube-data-api.md
7676
- Reporting API: fetchers/youtube-reporting-api.md
7777
- Merchant Center: fetchers/merchant-center-api.md
78+
- Google Analytics: fetchers/google-analytics-api.md

0 commit comments

Comments
 (0)