Skip to content

Commit

Permalink
Merge pull request #8 from dataproff/main
Browse files Browse the repository at this point in the history
Stream for User geo data (location of presence)
  • Loading branch information
DanielPDWalker authored Feb 7, 2023
2 parents 2726fbe + 1cb486c commit aa161bd
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tap-googleads"
version = "0.3.2"
version = "0.3.5"
description = "`tap-googleads` is a Singer tap for GoogleAds, built with the Meltano SDK for Singer Taps."
authors = ["AutoIDM", "Matatika"]
keywords = [
Expand Down
2 changes: 1 addition & 1 deletion tap_googleads/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GoogleAdsStream(RESTStream):
_LOG_REQUEST_METRIC_URLS: bool = True

_end_date = "'" + datetime.now().strftime("%Y-%m-%d") + "'"
_start_date = datetime.now() - timedelta(days=365)
_start_date = datetime.now() - timedelta(days=91)
_start_date = "'" + _start_date.strftime("%Y-%m-%d") + "'"

@property
Expand Down
58 changes: 58 additions & 0 deletions tap_googleads/schemas/geo_performance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"type": "object",
"properties": {
"customer_id": {
"type": "string"
},
"campaign": {
"type": "object",
"properties": {
"resourceName": {
"type": "string"
},
"status": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"metrics": {
"type": "object",
"properties": {
"clicks": {
"type": "string"
},
"costMicros": {
"type": "string"
},
"impressions": {
"type": "string"
},
"conversions": {
"type": "number"
}
}
},
"segments": {
"type": "object",
"properties": {
"date": {
"type": "string"
}
}
},
"geographicView": {
"type": "object",
"properties": {
"locationType": {
"type": "string"
},
"countryCriterionId": {
"type": "string"
}
}
}
}
}
33 changes: 32 additions & 1 deletion tap_googleads/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_records(self, context: Optional[dict]) -> Iterable[Dict[str, Any]]:

def get_child_context(self, record: dict, context: Optional[dict]) -> dict:
"""Return a context dictionary for child streams."""
return {"client_id": self.config.get("customer_id")}
return {"customer_id": self.config.get("customer_id")}


class GeotargetsStream(GoogleAdsStream):
Expand Down Expand Up @@ -317,3 +317,34 @@ def gaql(self):
]
replication_key = None
schema_filepath = SCHEMAS_DIR / "campaign_performance_by_location.json"

class GeoPerformance(ReportsStream):
"""Geo performance"""

@property
def gaql(self):
return f"""
SELECT
campaign.name,
campaign.status,
segments.date,
metrics.clicks,
metrics.cost_micros,
metrics.impressions,
metrics.conversions,
geographic_view.location_type,
geographic_view.country_criterion_id
FROM geographic_view
WHERE segments.date >= {self.start_date} and segments.date <= {self.end_date}
"""

records_jsonpath = "$.results[*]"
name = "geo_performance"
primary_keys = [
"geographic_view__country_criterion_id",
"customer_id",
"campaign__name",
"segments__date"
]
replication_key = None
schema_filepath = SCHEMAS_DIR / "geo_performance.json"
2 changes: 2 additions & 0 deletions tap_googleads/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CampaignPerformanceByGenderAndDevice,
CampaignPerformanceByLocation,
GeotargetsStream,
GeoPerformance
)

STREAM_TYPES = [
Expand All @@ -29,6 +30,7 @@
CampaignPerformanceByGenderAndDevice,
CampaignPerformanceByLocation,
GeotargetsStream,
GeoPerformance
]


Expand Down
2 changes: 1 addition & 1 deletion tap_googleads/tests/test_base_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_base_credentials_discovery(self):
catalog = TapGoogleAds(self.mock_config).discover_streams()

# expect valid catalog to be discovered
self.assertEqual(len(catalog), 10, "Total streams from default catalog")
self.assertEqual(len(catalog), 11, "Total streams from default catalog")

@responses.activate
def test_googleads_sync_accessible_customers(self):
Expand Down
2 changes: 1 addition & 1 deletion tap_googleads/tests/test_proxy_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_proxy_oauth_discovery(self):
catalog = TapGoogleAds(self.mock_config).discover_streams()

# Assert the correct number of default streams found
self.assertEqual(len(catalog), 10, "Total streams from default catalog")
self.assertEqual(len(catalog), 11, "Total streams from default catalog")

@responses.activate
def test_proxy_oauth_refresh(self):
Expand Down

0 comments on commit aa161bd

Please sign in to comment.