Skip to content

Commit 7443c5c

Browse files
add add-base64-credentials-option
1 parent 70e7f09 commit 7443c5c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

docs/supported-sources/google_analytics.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ The URI format for Google Analytics is as follows:
99
```plaintext
1010
googleanalytics://?credentials_path=/path/to/service/account.json&property_id=<property_id>
1111
```
12+
Alternatively, you can use base64 encoded credentials:
13+
14+
```
15+
googleanalytics://?credentials_base64=<base64_encoded_credentials>&property_id=<property_id>
16+
```
1217

1318
URI parameters:
1419
- `credentials_path`: The path to the service account JSON file.
15-
- `property_id`: It is a unique number that identifies a particular property on Google Analytics. [Follow this guide](https://developers.google.com/analytics/devguides/reporting/data/v1/property-id#what_is_my_property_id) if you don't know your property ID.
20+
- `property_id`: It is a unique number that identifies a particular property on Google Analytics. [Follow this guide](https://developers.google.com/analytics/devguides/reporting/data/v1/property-id#what_is_my_property_id) to know more about property ID.
1621

1722
## Setting up an Google Analytics Integration
1823
Google Analytics requires a few steps to set up an integration, please follow the guide dltHub [has built here](https://dlthub.com/docs/dlt-ecosystem/verified-sources/google_analytics#grab-google-service-account-credentials). Once you complete the guide, you should have an `.json` file and `project_id`.

ingestr/src/sources.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -1398,13 +1398,20 @@ def dlt_source(self, uri: str, table: str, **kwargs):
13981398
parse_uri = urlparse(uri)
13991399
source_fields = parse_qs(parse_uri.query)
14001400
cred_path = source_fields.get("credentials_path")
1401+
print(f"cred_path: {cred_path}")
1402+
cred_base64 = source_fields.get("credentials_base64")
14011403

1402-
if not cred_path:
1403-
raise ValueError("credentials_path is required to connect Google Analytics")
1404-
credentials = {}
1404+
if not cred_path and not cred_base64:
1405+
raise ValueError("credentials_path or credentials_base64 is required to connect Google Analytics")
14051406

1406-
with open(cred_path[0], "r") as f:
1407-
credentials = json.load(f)
1407+
credentials = {}
1408+
if cred_path:
1409+
with open(cred_path[0], "r") as f:
1410+
credentials = json.load(f)
1411+
elif cred_base64:
1412+
credentials = json.loads(
1413+
base64.b64decode(cred_base64[0]).decode("utf-8")
1414+
)
14081415

14091416
property_id = source_fields.get("property_id")
14101417
if not property_id:

0 commit comments

Comments
 (0)