Skip to content

Commit

Permalink
feat: add dimension and metric filters (#186)
Browse files Browse the repository at this point in the history
fixes #47

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
nmorvil and pre-commit-ci[bot] authored Apr 30, 2024
1 parent 932b6b8 commit 53cd5a0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tap_google_analytics/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,25 @@ def _lookup_data_type(self, field_type, attribute, dimensions_ref, metrics_ref):

@staticmethod
def _generate_report_definition(report_def_raw):
report_definition = {"metrics": [], "dimensions": []}
report_definition = {
"metrics": [],
"dimensions": [],
"metricFilter": None,
"dimensionFilter": None,
}

for dimension in report_def_raw["dimensions"]:
report_definition["dimensions"].append({"name": dimension})

for metric in report_def_raw["metrics"]:
report_definition["metrics"].append(Metric(name=metric))

if "metric_filter" in report_def_raw:
report_definition["metric_filter"] = report_def_raw["metric_filter"]

if "dimension_filter" in report_def_raw:
report_definition["dimension_filter"] = report_def_raw["dimension_filter"]

# Add segmentIds to the request if the stream contains them
if "segments" in report_def_raw:
report_definition["segments"] = [
Expand Down Expand Up @@ -253,6 +264,8 @@ def _query_api(self, report_definition, state_filter, pageToken=None) -> RunRepo
metrics=report_definition["metrics"],
date_ranges=[DateRange(start_date=state_filter, end_date=self.end_date)],
limit=self.page_size,
metric_filter=report_definition["metric_filter"],
dimension_filter=report_definition["dimension_filter"],
offset=(pageToken or 0) * self.page_size,
)

Expand Down

0 comments on commit 53cd5a0

Please sign in to comment.