Skip to content

Commit

Permalink
✨ Source Google Analytics Data API: Add spec parameter to convert `co…
Browse files Browse the repository at this point in the history
…nversions:purchase` to float (#34907)
  • Loading branch information
tolik0 authored and xiaohansong committed Feb 27, 2024
1 parent feb801e commit 84aef10
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 3cc2eafd-84aa-4dca-93af-322d9dfeec1a
dockerImageTag: 2.2.2
dockerImageTag: 2.3.0
dockerRepository: airbyte/source-google-analytics-data-api
documentationUrl: https://docs.airbyte.com/integrations/sources/google-analytics-data-api
githubIssueLabel: source-google-analytics-data-api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ def get_json_schema(self) -> Mapping[str, Any]:
}
)

# change the type of `conversions:purchase` metric from int to float: https://github.com/airbytehq/oncall/issues/4130
if self.config.get("convert_conversions_purchase", False) and "conversions:purchase" in schema["properties"]:
schema["properties"]["conversions:purchase"]["type"] = ["null", "float"]

return schema

def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
Expand Down Expand Up @@ -251,6 +255,10 @@ def parse_response(
metrics = [h.get("name") for h in r.get("metricHeaders", [{}])]
metrics_type_map = {h.get("name"): h.get("type") for h in r.get("metricHeaders", [{}]) if "name" in h}

# change the type of `conversions:purchase` metric from int to float: https://github.com/airbytehq/oncall/issues/4130
if self.config.get("convert_conversions_purchase", False) and "conversions:purchase" in metrics_type_map:
metrics_type_map["conversions:purchase"] = "TYPE_FLOAT"

for row in r.get("rows", []):
record = {
"property_id": self.config["property_id"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,13 @@
"description": "If false, each row with all metrics equal to 0 will not be returned. If true, these rows will be returned if they are not separately removed by a filter. More information is available in <a href=\"https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport#request-body\">the documentation</a>.",
"default": false,
"order": 6
},
"convert_conversions_purchase": {
"type": "boolean",
"title": "Convert `conversions:purchase` Metric to Float",
"description": "Determines whether the `conversions:purchase` metric, typically returned as an integer, should be converted to a float to prevent rounding. This option is useful if you're encountering issues with the API returning float values for the `conversions:purchase` field.",
"default": false,
"order": 7
}
}
},
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/google-analytics-data-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ The Google Analytics connector is subject to Google Analytics Data API quotas. P

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:--------------------------------------------------------------------------------|
| 2.3.0 | 2024-02-06 | [34907](https://github.com/airbytehq/airbyte/pull/34907) | Add new parameter to spec to convert `conversions:purchase` field to float |
| 2.2.2 | 2024-02-01 | [34708](https://github.com/airbytehq/airbyte/pull/34708) | Add rounding integer values that may be float |
| 2.2.1 | 2024-01-18 | [34352](https://github.com/airbytehq/airbyte/pull/34352) | Add incorrect custom reports config handling |
| 2.2.0 | 2024-01-10 | [34176](https://github.com/airbytehq/airbyte/pull/34176) | Add a report option keepEmptyRows |
Expand Down

0 comments on commit 84aef10

Please sign in to comment.