Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add filters to report_definition #48

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion tap_google_analytics/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _lookup_data_type(self, type, attribute, dimensions_ref, metrics_ref):

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

for dimension in report_def_raw["dimensions"]:
report_definition["dimensions"].append(
Expand All @@ -122,6 +122,15 @@ def _generate_report_definition(report_def_raw):
{"expression": metric.replace("ga_", "ga:")}
)

for filter in report_def_raw["filters"]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rickiesmooth thanks for the PR!

It looks like this is making filters a required entry in the report definition file. If someone upgrades to this version they'd need to update their definitions before it will run without error.

What do you think about making filters optional so its backwards compatible for users that already have the tap running and have no filters defined? It should be a simple change to use .get("filters", []) or a similar safety check.

report_definition["filters"].append(
{
"metricName": filter.metric_name,
"operator": filter.operator,
"comparisonValue": filter.comparison_value
}
)

# Add segmentIds to the request if the stream contains them
if "segments" in report_def_raw:
report_definition["segments"] = []
Expand Down Expand Up @@ -311,6 +320,7 @@ def _query_api(self, report_definition, state_filter, pageToken=None) -> dict:
"pageToken": pageToken,
"metrics": report_definition["metrics"],
"dimensions": report_definition["dimensions"],
"filters": report_definition["filters"],
}
]
}
Expand Down