Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix/canonicalize response #21

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Changelog
## v0.0.9
* Canonicalization response to match schema [#21](https://github.com/singer-io/tap-ga4/pull/21)
## v0.0.8
* Fixes canonicalization for custom dimensions/metrics [#20](https://github.com/singer-io/tap-ga4/pull/20)
## v0.0.7
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="tap-ga4",
version="0.0.8",
version="0.0.9",
description="Singer.io tap for extracting data",
author="Stitch",
url="http://singer.io",
Expand Down
11 changes: 11 additions & 0 deletions tap_ga4/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import singer
from singer import Transformer, get_bookmark, metadata, utils
from google.analytics.data_v1beta.types import (Metric, Dimension)

from tap_ga4.discover import to_snake_case


LOGGER = singer.get_logger()

DEFAULT_CONVERSION_WINDOW = 90
Expand Down Expand Up @@ -67,12 +71,19 @@ def generate_report_dates(start_date, end_date, request_window_size):
range_start = range_end + timedelta(days=1)


def transform_headers(dimension_headers, metric_headers):
dim_headers = [to_snake_case(dimension) for dimension in dimension_headers]
metric_headers = [to_snake_case(metric) for metric in metric_headers]
return dim_headers, metric_headers


def row_to_record(report, row, dimension_headers, metric_headers):
"""
Parse a RunReportResponse row into a single Singer record, with added
runtime info and PK.
"""
record = {}
dimension_headers, metric_headers = transform_headers(dimension_headers, metric_headers)
dimension_pairs = list(zip(dimension_headers, [dimension.value for dimension in row.dimension_values]))
record.update(dimension_pairs)
record.update(zip(metric_headers, [metric.value for metric in row.metric_values]))
Expand Down