digital-analytics-toolkit 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- digital_analytics_toolkit-0.1.0/LICENSE +55 -0
- digital_analytics_toolkit-0.1.0/PKG-INFO +292 -0
- digital_analytics_toolkit-0.1.0/README.md +271 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit/__init__.py +81 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit/bq_functions.py +97 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit/free_form_report_GA4.py +155 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit/funnel_report_GA4.py +269 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit/ga4_admin_functions.py +176 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit/ga4_audience.py +576 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit/gtm_functions.py +468 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit/utils.py +94 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit.egg-info/PKG-INFO +292 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit.egg-info/SOURCES.txt +16 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit.egg-info/dependency_links.txt +1 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit.egg-info/requires.txt +9 -0
- digital_analytics_toolkit-0.1.0/digital_analytics_toolkit.egg-info/top_level.txt +1 -0
- digital_analytics_toolkit-0.1.0/pyproject.toml +29 -0
- digital_analytics_toolkit-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Copyright (c) 2026 Isha Panchal and Kris Dsouza
|
|
2
|
+
|
|
3
|
+
PROPRIETARY SOFTWARE LICENSE
|
|
4
|
+
|
|
5
|
+
1. Ownership
|
|
6
|
+
|
|
7
|
+
This software, including its source code, documentation, and associated
|
|
8
|
+
materials, is proprietary software. All copyrights and other intellectual
|
|
9
|
+
property rights in the software are retained by the copyright holders.
|
|
10
|
+
|
|
11
|
+
2. Permission to Use
|
|
12
|
+
|
|
13
|
+
Permission is granted to any individual or organization to install and use
|
|
14
|
+
this software free of charge for personal, educational, research, or
|
|
15
|
+
commercial purposes.
|
|
16
|
+
|
|
17
|
+
3. Restrictions
|
|
18
|
+
|
|
19
|
+
Except as expressly permitted by this license, you may not:
|
|
20
|
+
|
|
21
|
+
- modify, alter, or create derivative works of the software;
|
|
22
|
+
- copy or reproduce the software for redistribution;
|
|
23
|
+
- redistribute, republish, sublicense, or sell the software;
|
|
24
|
+
- package or incorporate the software into another publicly distributed
|
|
25
|
+
software package;
|
|
26
|
+
- publish modified or unmodified copies of the software;
|
|
27
|
+
- claim ownership of the software or its source code.
|
|
28
|
+
|
|
29
|
+
4. Source Code
|
|
30
|
+
|
|
31
|
+
The source code is proprietary and is not licensed for public access,
|
|
32
|
+
modification, or redistribution. The availability of a package through
|
|
33
|
+
PyPI does not grant any rights to access, modify, or redistribute the
|
|
34
|
+
source code beyond the rights explicitly granted by this license.
|
|
35
|
+
|
|
36
|
+
5. Contributions and Modifications
|
|
37
|
+
|
|
38
|
+
Only individuals expressly authorized by the copyright holders may modify
|
|
39
|
+
the original source code or contribute modifications to the project.
|
|
40
|
+
|
|
41
|
+
6. No Warranty
|
|
42
|
+
|
|
43
|
+
The software is provided "AS IS", without warranty of any kind, express or
|
|
44
|
+
implied. The copyright holders shall not be liable for any claim, damages,
|
|
45
|
+
or other liability arising from the use of the software.
|
|
46
|
+
|
|
47
|
+
7. Termination
|
|
48
|
+
|
|
49
|
+
Any rights granted under this license terminate automatically if you
|
|
50
|
+
violate the terms of this license.
|
|
51
|
+
|
|
52
|
+
8. Copyright
|
|
53
|
+
|
|
54
|
+
Copyright (c) 2026 Isha Panchal and Kris Dsouza.
|
|
55
|
+
All rights reserved.
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: digital-analytics-toolkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Toolkit for Google Analytics, Google Tag Manager, and BigQuery workflows
|
|
5
|
+
Author: Isha Panchal, Kris Dsouza
|
|
6
|
+
Maintainer-email: Isha Panchal <hacker.knight177@gmail.com>, Kris Dsouza <kris.dsouza64@gmail.com>
|
|
7
|
+
License-Expression: LicenseRef-Proprietary
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: pandas
|
|
12
|
+
Requires-Dist: numpy
|
|
13
|
+
Requires-Dist: google-auth
|
|
14
|
+
Requires-Dist: google-analytics-data
|
|
15
|
+
Requires-Dist: google-analytics-admin
|
|
16
|
+
Requires-Dist: google-api-python-client
|
|
17
|
+
Requires-Dist: gspread
|
|
18
|
+
Requires-Dist: google-cloud-bigquery
|
|
19
|
+
Requires-Dist: db-dtypes
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# 🚀 Digital Analytics Toolkit
|
|
23
|
+
|
|
24
|
+
### A Python toolkit for Google Analytics 4, Google Tag Manager, and BigQuery workflows
|
|
25
|
+
|
|
26
|
+
**Digital Analytics Toolkit** is a Python library designed to streamline GA4 reporting, GA4 administration, audience management, GTM container inspection, and BigQuery querying through reusable Python functions and clients.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 📦 Installation
|
|
31
|
+
|
|
32
|
+
Install the latest release from PyPI:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install digital-analytics-toolkit
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For future upgrade:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install --upgrade digital-analytics-toolkit
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 🔐 Authentication
|
|
47
|
+
|
|
48
|
+
Digital Analytics Toolkit supports **Service Account Key JSON files** and **Google OAuth2 Credentials**.
|
|
49
|
+
|
|
50
|
+
1. Create a Service Account in the [Google Cloud Console](https://console.cloud.google.com/).
|
|
51
|
+
2. Enable necessary APIs:
|
|
52
|
+
- Google Analytics Data API
|
|
53
|
+
- Google Analytics Admin API
|
|
54
|
+
- Google Tag Manager API
|
|
55
|
+
- BigQuery API
|
|
56
|
+
3. Download the JSON key file and share your GA4 property / GTM account access with the service account email.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🧩 Features & Module Usage
|
|
61
|
+
|
|
62
|
+
The toolkit is organized into 4 primary functional areas:
|
|
63
|
+
|
|
64
|
+
1. [GA4 Free-Form & Funnel Reporting](#1-ga4-reporting)
|
|
65
|
+
2. [GA4 Admin & Audience Management](#2-ga4-admin--audiences)
|
|
66
|
+
3. [Google Tag Manager (GTM) Operations](#3-google-tag-manager-gtm)
|
|
67
|
+
4. [BigQuery Integration](#4-bigquery-integration)
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
### 1. GA4 Reporting
|
|
72
|
+
|
|
73
|
+
#### 📊 Free-Form Reports (`free_form_report_GA4`)
|
|
74
|
+
Run custom GA4 reports specifying metrics, dimensions, date ranges, and optional dimension/metric filters.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from digital_analytics_toolkit import free_form_report_GA4, dimension_filter_generation
|
|
78
|
+
|
|
79
|
+
# Initialize client
|
|
80
|
+
report_client = free_form_report_GA4(
|
|
81
|
+
service_account_file="path/to/service_account.json",
|
|
82
|
+
property_id="123456789"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Optional: Generate dimension filter
|
|
86
|
+
dim_filter = dimension_filter_generation(
|
|
87
|
+
operator="CONTAINS",
|
|
88
|
+
value="Organic",
|
|
89
|
+
dimension_name="sessionDefaultChannelGroup"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
# Generate report
|
|
93
|
+
df = report_client.free_form_report(
|
|
94
|
+
start_date="30daysAgo",
|
|
95
|
+
end_date="today",
|
|
96
|
+
metrics=["activeUsers", "eventCount", "conversions"],
|
|
97
|
+
dimensions=["date", "sessionDefaultChannelGroup"],
|
|
98
|
+
dimension_filter=dim_filter
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
print(df.head())
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### 🏆 Multi-Step Funnel Reports (`Funnel_Reports`)
|
|
105
|
+
Generate multi-step funnel analysis with support for breakdown dimensions based on funnel step definitions configured in Google Sheets.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from digital_analytics_toolkit import Funnel_Reports
|
|
109
|
+
|
|
110
|
+
funnel = Funnel_Reports(
|
|
111
|
+
reporting_client="path/to/service_account.json",
|
|
112
|
+
prop_id="123456789"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# Run funnel report using steps defined in a Google Sheet
|
|
116
|
+
response = funnel.funnel_report(
|
|
117
|
+
startDate="2024-01-01",
|
|
118
|
+
endDate="2024-01-31",
|
|
119
|
+
file_n="My_Funnel_Steps_Sheet_Name",
|
|
120
|
+
breakdown="deviceCategory",
|
|
121
|
+
breakdown_limit="5"
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### 📜 Dimension & Metric Metadata (`get_dimension_metric`)
|
|
126
|
+
Fetch all available custom & standard dimensions/metrics for a GA4 property and export to CSV.
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from digital_analytics_toolkit import utils
|
|
130
|
+
|
|
131
|
+
utils.get_dimension_metric(
|
|
132
|
+
service_account_file="path/to/service_account.json",
|
|
133
|
+
property_id="123456789",
|
|
134
|
+
file_name="ga4_dimensions_metrics"
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### 2. GA4 Admin & Audiences
|
|
141
|
+
|
|
142
|
+
#### 🏢 Accounts & Property Discovery
|
|
143
|
+
Discover accounts, properties, key events (conversions), and BigQuery links.
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from google.oauth2 import service_account
|
|
147
|
+
from digital_analytics_toolkit import (
|
|
148
|
+
get_ga4_accounts_list,
|
|
149
|
+
get_ga4_properties_list,
|
|
150
|
+
get_ga4_property_keyEvents,
|
|
151
|
+
get_ga4_property_bq_link
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
creds = service_account.Credentials.from_service_account_file(
|
|
155
|
+
"path/to/service_account.json",
|
|
156
|
+
scopes=["https://www.googleapis.com/auth/analytics.readonly"]
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
# List accounts & properties
|
|
160
|
+
accounts_df = get_ga4_accounts_list(creds)
|
|
161
|
+
properties_df = get_ga4_properties_list(creds, account_id="12345678")
|
|
162
|
+
|
|
163
|
+
# Key events & BigQuery export status
|
|
164
|
+
key_events_df = get_ga4_property_keyEvents(creds, property_id="123456789")
|
|
165
|
+
bq_links_df = get_ga4_property_bq_link(creds, property_id="123456789")
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### 🎯 Audience Creation (`GA4AudienceClient`)
|
|
169
|
+
Programmatically construct and create GA4 audiences using a simplified dictionary condition language.
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from digital_analytics_toolkit import GA4AudienceClient
|
|
173
|
+
|
|
174
|
+
client = GA4AudienceClient(credentials_path="path/to/service_account.json")
|
|
175
|
+
|
|
176
|
+
audience = client.create_audience(
|
|
177
|
+
property_id="123456789",
|
|
178
|
+
display_name="High Intent Purchasers",
|
|
179
|
+
description="Users with > 3 sessions who completed a purchase",
|
|
180
|
+
membership_duration_days=30,
|
|
181
|
+
scope="ACROSS_ALL_SESSIONS",
|
|
182
|
+
include_conditions=[
|
|
183
|
+
{"type": "event", "event_name": "purchase"},
|
|
184
|
+
{"type": "numeric", "field_name": "sessionCount", "operation": "GREATER_THAN", "value": 3}
|
|
185
|
+
]
|
|
186
|
+
)
|
|
187
|
+
print(f"Created audience: {audience.name}")
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### 3. Google Tag Manager (GTM)
|
|
193
|
+
|
|
194
|
+
Inspect accounts, containers, workspaces, tags, triggers, variables, built-in variables, and custom templates.
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
from google.oauth2 import service_account
|
|
198
|
+
from digital_analytics_toolkit import (
|
|
199
|
+
get_accounts,
|
|
200
|
+
get_containers,
|
|
201
|
+
get_workspaces,
|
|
202
|
+
get_tags,
|
|
203
|
+
get_triggers,
|
|
204
|
+
get_variables,
|
|
205
|
+
get_built_in_variables,
|
|
206
|
+
get_custom_templates
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
creds = service_account.Credentials.from_service_account_file(
|
|
210
|
+
"path/to/service_account.json",
|
|
211
|
+
scopes=["https://www.googleapis.com/auth/tagmanager.readonly"]
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
# List accounts & containers
|
|
215
|
+
gtm_accounts = get_accounts(creds)
|
|
216
|
+
containers_df = get_containers(creds, account_id="123456")
|
|
217
|
+
|
|
218
|
+
# Inspect workspace assets
|
|
219
|
+
workspace_id = get_workspaces(creds, account_id="123456", container_id="987654")
|
|
220
|
+
tags = get_tags(creds, account_id="123456", container_id="987654", workspace_id=workspace_id)
|
|
221
|
+
triggers = get_triggers(creds, account_id="123456", container_id="987654", workspace_id=workspace_id)
|
|
222
|
+
variables = get_variables(creds, account_id="123456", container_id="987654", workspace_id=workspace_id)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
### 4. BigQuery Integration
|
|
228
|
+
|
|
229
|
+
Run custom SQL queries or extract full tables directly into Pandas DataFrames.
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
from digital_analytics_toolkit import bq_functions
|
|
233
|
+
|
|
234
|
+
service_account_file = "path/to/service_account.json"
|
|
235
|
+
project_id = "my-gcp-project"
|
|
236
|
+
|
|
237
|
+
# List Datasets
|
|
238
|
+
datasets = bq_functions.list_bq_datasets(credentials=None, gcp_project_id=project_id)
|
|
239
|
+
|
|
240
|
+
# Execute SQL query to DataFrame
|
|
241
|
+
query = """
|
|
242
|
+
SELECT event_name, COUNT(1) AS event_count
|
|
243
|
+
FROM `my-gcp-project.analytics_123456789.events_*`
|
|
244
|
+
WHERE _TABLE_SUFFIX = FORMAT_DATE('%Y%m%d', CURRENT_DATE())
|
|
245
|
+
GROUP BY 1
|
|
246
|
+
"""
|
|
247
|
+
df = bq_functions.get_ga4_data_from_bq(
|
|
248
|
+
project_id=project_id,
|
|
249
|
+
query=query,
|
|
250
|
+
service_account_file=service_account_file
|
|
251
|
+
)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## 🛠 Project Structure
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
digital-analytics-toolkit/
|
|
260
|
+
├── pyproject.toml
|
|
261
|
+
├── README.md
|
|
262
|
+
└── digital_analytics_toolkit/
|
|
263
|
+
├── __init__.py # Package entrypoint & exported symbols
|
|
264
|
+
├── free_form_report_GA4.py # GA4 Free-form reporting & dimension filter generation
|
|
265
|
+
├── funnel_report_GA4.py # GA4 Funnel report engine
|
|
266
|
+
├── ga4_admin_functions.py # GA4 Admin API helpers (Accounts, Properties, Key Events, BQ Links)
|
|
267
|
+
├── ga4_audience.py # GA4 Audience creation & condition parser
|
|
268
|
+
├── gtm_functions.py # Google Tag Manager (GTM) API helper functions
|
|
269
|
+
├── bq_functions.py # BigQuery query execution & dataset tools
|
|
270
|
+
└── utils.py # Utility functions & metadata extractors
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## 💬 Support & Inquiries
|
|
276
|
+
|
|
277
|
+
- For questions, bug reports, or feature requests, contact: **[hacker.knight177@gmail.com](mailto:hacker.knight177@gmail.com)** or **[kris.dsouza64@gmail.com](mailto:kris.dsouza64@gmail.com)**
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## 📄 License
|
|
282
|
+
|
|
283
|
+
Digital Analytics Toolkit is proprietary software.
|
|
284
|
+
|
|
285
|
+
It is free to install and use for personal, educational, research,
|
|
286
|
+
and commercial purposes.
|
|
287
|
+
|
|
288
|
+
Modification, redistribution, sublicensing, resale, and creation of
|
|
289
|
+
derivative works are not permitted without explicit written
|
|
290
|
+
permission from the copyright holders.
|
|
291
|
+
|
|
292
|
+
See the [LICENSE](LICENSE) file for the complete terms.
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# 🚀 Digital Analytics Toolkit
|
|
2
|
+
|
|
3
|
+
### A Python toolkit for Google Analytics 4, Google Tag Manager, and BigQuery workflows
|
|
4
|
+
|
|
5
|
+
**Digital Analytics Toolkit** is a Python library designed to streamline GA4 reporting, GA4 administration, audience management, GTM container inspection, and BigQuery querying through reusable Python functions and clients.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 📦 Installation
|
|
10
|
+
|
|
11
|
+
Install the latest release from PyPI:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install digital-analytics-toolkit
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For future upgrade:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install --upgrade digital-analytics-toolkit
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 🔐 Authentication
|
|
26
|
+
|
|
27
|
+
Digital Analytics Toolkit supports **Service Account Key JSON files** and **Google OAuth2 Credentials**.
|
|
28
|
+
|
|
29
|
+
1. Create a Service Account in the [Google Cloud Console](https://console.cloud.google.com/).
|
|
30
|
+
2. Enable necessary APIs:
|
|
31
|
+
- Google Analytics Data API
|
|
32
|
+
- Google Analytics Admin API
|
|
33
|
+
- Google Tag Manager API
|
|
34
|
+
- BigQuery API
|
|
35
|
+
3. Download the JSON key file and share your GA4 property / GTM account access with the service account email.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 🧩 Features & Module Usage
|
|
40
|
+
|
|
41
|
+
The toolkit is organized into 4 primary functional areas:
|
|
42
|
+
|
|
43
|
+
1. [GA4 Free-Form & Funnel Reporting](#1-ga4-reporting)
|
|
44
|
+
2. [GA4 Admin & Audience Management](#2-ga4-admin--audiences)
|
|
45
|
+
3. [Google Tag Manager (GTM) Operations](#3-google-tag-manager-gtm)
|
|
46
|
+
4. [BigQuery Integration](#4-bigquery-integration)
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### 1. GA4 Reporting
|
|
51
|
+
|
|
52
|
+
#### 📊 Free-Form Reports (`free_form_report_GA4`)
|
|
53
|
+
Run custom GA4 reports specifying metrics, dimensions, date ranges, and optional dimension/metric filters.
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from digital_analytics_toolkit import free_form_report_GA4, dimension_filter_generation
|
|
57
|
+
|
|
58
|
+
# Initialize client
|
|
59
|
+
report_client = free_form_report_GA4(
|
|
60
|
+
service_account_file="path/to/service_account.json",
|
|
61
|
+
property_id="123456789"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Optional: Generate dimension filter
|
|
65
|
+
dim_filter = dimension_filter_generation(
|
|
66
|
+
operator="CONTAINS",
|
|
67
|
+
value="Organic",
|
|
68
|
+
dimension_name="sessionDefaultChannelGroup"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Generate report
|
|
72
|
+
df = report_client.free_form_report(
|
|
73
|
+
start_date="30daysAgo",
|
|
74
|
+
end_date="today",
|
|
75
|
+
metrics=["activeUsers", "eventCount", "conversions"],
|
|
76
|
+
dimensions=["date", "sessionDefaultChannelGroup"],
|
|
77
|
+
dimension_filter=dim_filter
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
print(df.head())
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### 🏆 Multi-Step Funnel Reports (`Funnel_Reports`)
|
|
84
|
+
Generate multi-step funnel analysis with support for breakdown dimensions based on funnel step definitions configured in Google Sheets.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from digital_analytics_toolkit import Funnel_Reports
|
|
88
|
+
|
|
89
|
+
funnel = Funnel_Reports(
|
|
90
|
+
reporting_client="path/to/service_account.json",
|
|
91
|
+
prop_id="123456789"
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Run funnel report using steps defined in a Google Sheet
|
|
95
|
+
response = funnel.funnel_report(
|
|
96
|
+
startDate="2024-01-01",
|
|
97
|
+
endDate="2024-01-31",
|
|
98
|
+
file_n="My_Funnel_Steps_Sheet_Name",
|
|
99
|
+
breakdown="deviceCategory",
|
|
100
|
+
breakdown_limit="5"
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### 📜 Dimension & Metric Metadata (`get_dimension_metric`)
|
|
105
|
+
Fetch all available custom & standard dimensions/metrics for a GA4 property and export to CSV.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from digital_analytics_toolkit import utils
|
|
109
|
+
|
|
110
|
+
utils.get_dimension_metric(
|
|
111
|
+
service_account_file="path/to/service_account.json",
|
|
112
|
+
property_id="123456789",
|
|
113
|
+
file_name="ga4_dimensions_metrics"
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### 2. GA4 Admin & Audiences
|
|
120
|
+
|
|
121
|
+
#### 🏢 Accounts & Property Discovery
|
|
122
|
+
Discover accounts, properties, key events (conversions), and BigQuery links.
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from google.oauth2 import service_account
|
|
126
|
+
from digital_analytics_toolkit import (
|
|
127
|
+
get_ga4_accounts_list,
|
|
128
|
+
get_ga4_properties_list,
|
|
129
|
+
get_ga4_property_keyEvents,
|
|
130
|
+
get_ga4_property_bq_link
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
creds = service_account.Credentials.from_service_account_file(
|
|
134
|
+
"path/to/service_account.json",
|
|
135
|
+
scopes=["https://www.googleapis.com/auth/analytics.readonly"]
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# List accounts & properties
|
|
139
|
+
accounts_df = get_ga4_accounts_list(creds)
|
|
140
|
+
properties_df = get_ga4_properties_list(creds, account_id="12345678")
|
|
141
|
+
|
|
142
|
+
# Key events & BigQuery export status
|
|
143
|
+
key_events_df = get_ga4_property_keyEvents(creds, property_id="123456789")
|
|
144
|
+
bq_links_df = get_ga4_property_bq_link(creds, property_id="123456789")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### 🎯 Audience Creation (`GA4AudienceClient`)
|
|
148
|
+
Programmatically construct and create GA4 audiences using a simplified dictionary condition language.
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from digital_analytics_toolkit import GA4AudienceClient
|
|
152
|
+
|
|
153
|
+
client = GA4AudienceClient(credentials_path="path/to/service_account.json")
|
|
154
|
+
|
|
155
|
+
audience = client.create_audience(
|
|
156
|
+
property_id="123456789",
|
|
157
|
+
display_name="High Intent Purchasers",
|
|
158
|
+
description="Users with > 3 sessions who completed a purchase",
|
|
159
|
+
membership_duration_days=30,
|
|
160
|
+
scope="ACROSS_ALL_SESSIONS",
|
|
161
|
+
include_conditions=[
|
|
162
|
+
{"type": "event", "event_name": "purchase"},
|
|
163
|
+
{"type": "numeric", "field_name": "sessionCount", "operation": "GREATER_THAN", "value": 3}
|
|
164
|
+
]
|
|
165
|
+
)
|
|
166
|
+
print(f"Created audience: {audience.name}")
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
### 3. Google Tag Manager (GTM)
|
|
172
|
+
|
|
173
|
+
Inspect accounts, containers, workspaces, tags, triggers, variables, built-in variables, and custom templates.
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from google.oauth2 import service_account
|
|
177
|
+
from digital_analytics_toolkit import (
|
|
178
|
+
get_accounts,
|
|
179
|
+
get_containers,
|
|
180
|
+
get_workspaces,
|
|
181
|
+
get_tags,
|
|
182
|
+
get_triggers,
|
|
183
|
+
get_variables,
|
|
184
|
+
get_built_in_variables,
|
|
185
|
+
get_custom_templates
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
creds = service_account.Credentials.from_service_account_file(
|
|
189
|
+
"path/to/service_account.json",
|
|
190
|
+
scopes=["https://www.googleapis.com/auth/tagmanager.readonly"]
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
# List accounts & containers
|
|
194
|
+
gtm_accounts = get_accounts(creds)
|
|
195
|
+
containers_df = get_containers(creds, account_id="123456")
|
|
196
|
+
|
|
197
|
+
# Inspect workspace assets
|
|
198
|
+
workspace_id = get_workspaces(creds, account_id="123456", container_id="987654")
|
|
199
|
+
tags = get_tags(creds, account_id="123456", container_id="987654", workspace_id=workspace_id)
|
|
200
|
+
triggers = get_triggers(creds, account_id="123456", container_id="987654", workspace_id=workspace_id)
|
|
201
|
+
variables = get_variables(creds, account_id="123456", container_id="987654", workspace_id=workspace_id)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
### 4. BigQuery Integration
|
|
207
|
+
|
|
208
|
+
Run custom SQL queries or extract full tables directly into Pandas DataFrames.
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from digital_analytics_toolkit import bq_functions
|
|
212
|
+
|
|
213
|
+
service_account_file = "path/to/service_account.json"
|
|
214
|
+
project_id = "my-gcp-project"
|
|
215
|
+
|
|
216
|
+
# List Datasets
|
|
217
|
+
datasets = bq_functions.list_bq_datasets(credentials=None, gcp_project_id=project_id)
|
|
218
|
+
|
|
219
|
+
# Execute SQL query to DataFrame
|
|
220
|
+
query = """
|
|
221
|
+
SELECT event_name, COUNT(1) AS event_count
|
|
222
|
+
FROM `my-gcp-project.analytics_123456789.events_*`
|
|
223
|
+
WHERE _TABLE_SUFFIX = FORMAT_DATE('%Y%m%d', CURRENT_DATE())
|
|
224
|
+
GROUP BY 1
|
|
225
|
+
"""
|
|
226
|
+
df = bq_functions.get_ga4_data_from_bq(
|
|
227
|
+
project_id=project_id,
|
|
228
|
+
query=query,
|
|
229
|
+
service_account_file=service_account_file
|
|
230
|
+
)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## 🛠 Project Structure
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
digital-analytics-toolkit/
|
|
239
|
+
├── pyproject.toml
|
|
240
|
+
├── README.md
|
|
241
|
+
└── digital_analytics_toolkit/
|
|
242
|
+
├── __init__.py # Package entrypoint & exported symbols
|
|
243
|
+
├── free_form_report_GA4.py # GA4 Free-form reporting & dimension filter generation
|
|
244
|
+
├── funnel_report_GA4.py # GA4 Funnel report engine
|
|
245
|
+
├── ga4_admin_functions.py # GA4 Admin API helpers (Accounts, Properties, Key Events, BQ Links)
|
|
246
|
+
├── ga4_audience.py # GA4 Audience creation & condition parser
|
|
247
|
+
├── gtm_functions.py # Google Tag Manager (GTM) API helper functions
|
|
248
|
+
├── bq_functions.py # BigQuery query execution & dataset tools
|
|
249
|
+
└── utils.py # Utility functions & metadata extractors
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## 💬 Support & Inquiries
|
|
255
|
+
|
|
256
|
+
- For questions, bug reports, or feature requests, contact: **[hacker.knight177@gmail.com](mailto:hacker.knight177@gmail.com)** or **[kris.dsouza64@gmail.com](mailto:kris.dsouza64@gmail.com)**
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## 📄 License
|
|
261
|
+
|
|
262
|
+
Digital Analytics Toolkit is proprietary software.
|
|
263
|
+
|
|
264
|
+
It is free to install and use for personal, educational, research,
|
|
265
|
+
and commercial purposes.
|
|
266
|
+
|
|
267
|
+
Modification, redistribution, sublicensing, resale, and creation of
|
|
268
|
+
derivative works are not permitted without explicit written
|
|
269
|
+
permission from the copyright holders.
|
|
270
|
+
|
|
271
|
+
See the [LICENSE](LICENSE) file for the complete terms.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from . import (
|
|
2
|
+
bq_functions,
|
|
3
|
+
free_form_report_GA4,
|
|
4
|
+
funnel_report_GA4,
|
|
5
|
+
ga4_admin_functions,
|
|
6
|
+
ga4_audience,
|
|
7
|
+
gtm_functions,
|
|
8
|
+
utils,
|
|
9
|
+
)
|
|
10
|
+
from .bq_functions import (
|
|
11
|
+
get_from_bigquery,
|
|
12
|
+
get_ga4_data_from_bq,
|
|
13
|
+
list_bq_datasets,
|
|
14
|
+
)
|
|
15
|
+
from .free_form_report_GA4 import dimension_filter_generation, free_form_report_GA4
|
|
16
|
+
from .funnel_report_GA4 import Funnel_Reports
|
|
17
|
+
from .ga4_admin_functions import (
|
|
18
|
+
get_ga4_accounts_list,
|
|
19
|
+
get_ga4_properties_list,
|
|
20
|
+
get_ga4_property_bq_link,
|
|
21
|
+
get_ga4_property_keyEvents,
|
|
22
|
+
)
|
|
23
|
+
from .ga4_audience import (
|
|
24
|
+
GA4AudienceClient,
|
|
25
|
+
GA4AudienceError,
|
|
26
|
+
build_admin_client,
|
|
27
|
+
create_audience,
|
|
28
|
+
)
|
|
29
|
+
from .gtm_functions import (
|
|
30
|
+
get_accounts,
|
|
31
|
+
get_built_in_variables,
|
|
32
|
+
get_containers,
|
|
33
|
+
get_custom_templates,
|
|
34
|
+
get_tags,
|
|
35
|
+
get_triggers,
|
|
36
|
+
get_variables,
|
|
37
|
+
get_workspaces,
|
|
38
|
+
getLatestVersionHeader,
|
|
39
|
+
)
|
|
40
|
+
from .utils import get_dimension_metric
|
|
41
|
+
|
|
42
|
+
__version__ = "0.1.0"
|
|
43
|
+
|
|
44
|
+
__all__ = [
|
|
45
|
+
# Submodules
|
|
46
|
+
"bq_functions",
|
|
47
|
+
"ga4_admin_functions",
|
|
48
|
+
"ga4_audience",
|
|
49
|
+
"gtm_functions",
|
|
50
|
+
"utils",
|
|
51
|
+
# Reporting
|
|
52
|
+
"Funnel_Reports",
|
|
53
|
+
"free_form_report_GA4",
|
|
54
|
+
"dimension_filter_generation",
|
|
55
|
+
# GA4 Admin
|
|
56
|
+
"get_ga4_accounts_list",
|
|
57
|
+
"get_ga4_properties_list",
|
|
58
|
+
"get_ga4_property_keyEvents",
|
|
59
|
+
"get_ga4_property_bq_link",
|
|
60
|
+
# Audiences
|
|
61
|
+
"GA4AudienceClient",
|
|
62
|
+
"create_audience",
|
|
63
|
+
"build_admin_client",
|
|
64
|
+
"GA4AudienceError",
|
|
65
|
+
# GTM
|
|
66
|
+
"get_accounts",
|
|
67
|
+
"get_containers",
|
|
68
|
+
"get_workspaces",
|
|
69
|
+
"getLatestVersionHeader",
|
|
70
|
+
"get_tags",
|
|
71
|
+
"get_variables",
|
|
72
|
+
"get_triggers",
|
|
73
|
+
"get_built_in_variables",
|
|
74
|
+
"get_custom_templates",
|
|
75
|
+
# BigQuery
|
|
76
|
+
"list_bq_datasets",
|
|
77
|
+
"get_from_bigquery",
|
|
78
|
+
"get_ga4_data_from_bq",
|
|
79
|
+
# Utilities
|
|
80
|
+
"get_dimension_metric",
|
|
81
|
+
]
|