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

Revert "HGI-6435 / Add streams for sessions and breakdown analytics reports" #85

Open
wants to merge 1 commit into
base: HGI-6444
Choose a base branch
from
Open
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: 1 addition & 1 deletion tap_hubspot_beta/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class hubspotStream(RESTStream):

url_base = "https://api.hubapi.com/"
base_properties = []
additional_params = {}
additional_prarams = {}
properties_url = None
page_size = 100

Expand Down
2 changes: 1 addition & 1 deletion tap_hubspot_beta/client_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_url_params(
params["count"] = self.page_size
if next_page_token:
params.update(next_page_token)
params.update(self.additional_params)
params.update(self.additional_prarams)
params["property"] = self.selected_properties
return params

Expand Down
2 changes: 1 addition & 1 deletion tap_hubspot_beta/client_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def get_url_params(
"""Return a dictionary of values to be used in URL parameterization."""
params: dict = {}
params["limit"] = self.page_size
params.update(self.additional_params)
params.update(self.additional_prarams)
if self.properties_url:
params["properties"] = ",".join(self.selected_properties)
if next_page_token:
Expand Down
176 changes: 2 additions & 174 deletions tap_hubspot_beta/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from tap_hubspot_beta.client_v1 import hubspotV1Stream
from tap_hubspot_beta.client_v3 import hubspotV3SearchStream, hubspotV3Stream, hubspotV3SingleSearchStream, AssociationsV3ParentStream
from tap_hubspot_beta.client_v4 import hubspotV4Stream
import time
import pytz
from singer_sdk.helpers._state import log_sort_error
from pendulum import parse
Expand All @@ -33,7 +34,6 @@
th.Property("associationTypes", th.CustomType({"type": ["array", "object"]})),
).to_dict()


class AccountStream(hubspotV1Stream):
"""Account Stream"""

Expand Down Expand Up @@ -161,7 +161,7 @@ class ContactsStream(hubspotV1Stream):
records_jsonpath = "$.contacts[*]"
primary_keys = ["vid"]
replication_key = None
additional_params = dict(showListMemberships=True)
additional_prarams = dict(showListMemberships=True)
properties_url = "properties/v1/contacts/properties"

base_properties = [
Expand Down Expand Up @@ -1743,178 +1743,6 @@ class AssociationTasksDealsStream(AssociationTasksStream):
name = "associations_tasks_deals"
path = "crm/v4/associations/tasks/deals/batch/read"


breakdown_properties_list = [
th.Property("breakdown", th.StringType),
th.Property("others", th.IntegerType),
th.Property("otherCampaigns", th.IntegerType),
th.Property("mobile", th.IntegerType),
th.Property("desktop", th.IntegerType),
th.Property("organicSearch", th.IntegerType),
th.Property("paidSearch", th.IntegerType),
th.Property("paidSocial", th.IntegerType),
th.Property("socialMedia", th.IntegerType),
th.Property("directTraffic", th.IntegerType),
th.Property("referrals", th.IntegerType),
th.Property("date", th.DateType),
th.Property("rawViews", th.IntegerType),
th.Property("visits", th.IntegerType),
th.Property("visitors", th.IntegerType),
th.Property("leads", th.IntegerType),
th.Property("contacts", th.IntegerType),
th.Property("subscribers", th.IntegerType),
th.Property("opportunities", th.IntegerType),
th.Property("customers", th.IntegerType),
th.Property("pageviewsPerSession", th.NumberType),
th.Property("bounceRate", th.NumberType),
th.Property("timePerSession", th.NumberType),
th.Property("newVisitorSessionRate", th.NumberType),
th.Property("sessionToContactRate", th.NumberType),
th.Property("contactToCustomerRate", th.NumberType),
]

class SessionAnalyticsReportsBaseStream(hubspotV3Stream):

schema = th.PropertiesList(
*breakdown_properties_list
).to_dict()

def parse_response(self, response: requests.Response):
res_json = response.json()
for date_str, list_data_obj in res_json.items():
for data_obj in list_data_obj:
data_obj["date"] = date_str
yield data_obj


class SessionAnalyticsDailyReportsStream(SessionAnalyticsReportsBaseStream):
name = "session_analytics_daily_reports"
path = "analytics/v2/reports/sessions/daily"


class SessionAnalyticsWeeklyReportsStream(SessionAnalyticsReportsBaseStream):
name = "session_analytics_weekly_reports"
path = "analytics/v2/reports/sessions/weekly"


class SessionAnalyticsMonthlyReportsStream(SessionAnalyticsReportsBaseStream):
name = "session_analytics_monthly_reports"
path = "analytics/v2/reports/sessions/monthly"


class SessionAnalyticsTotalReportStream(SessionAnalyticsReportsBaseStream):
name = "session_analytics_total_report"
path = "analytics/v2/reports/sessions/total"
__offset = 0

def parse_response(self, response: requests.Response) -> Iterable[Dict]:
yield from (row for row in response.json().get('breakdowns', [{}]))

@property
def additional_params(self):
return dict(offset=self.__offset)

def get_next_page_token(self, response: requests.Response, previous_token: Any | None) -> Any | None:
offset = response.json().get('offset', 0)
if not offset:
return None

total = response.json().get('total')
if not total or offset >= total:
return None

if not self.page_size:
self.page_size = offset

self.__offset += self.page_size
return self.additional_params


class BreakdownsAnalyticsReportsBaseStream(hubspotV3Stream):
page_size = None
__offset = 0
__current_d1 = None

@property
def d1_options(self):
raise NotImplementedError #['regions', 'us', 'organic', 'referrals', 'social', 'test']

schema = th.PropertiesList(
*breakdown_properties_list,
th.Property("d1", th.StringType)
).to_dict()

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
d1_options = self._config.get(f"d1_options_{self.name}")
if d1_options and isinstance(d1_options, list):
self.__d1_options = d1_options
elif d1_options and isinstance(d1_options, str):
self.__d1_options = [d1_options]
else:
self.__d1_options = self.d1_options

@property
def d1(self):
if not self.__current_d1:
self.update_d1()
return self.__current_d1

@property
def additional_params(self):
return dict(offset=self.__offset, d1=self.d1)

def update_d1(self):
self.__current_d1 = self.__d1_options.pop()

def reset_offset(self):
self.__offset = 0

def parse_response(self, response: requests.Response) -> Iterable[Dict]:
for row in response.json().get('breakdowns', [{}]):
row["d1"] = self.d1
yield row

def next_token(self):
if len(self.__d1_options) == 0:
return None

self.update_d1()
self.reset_offset()
return self.additional_params

def get_next_page_token(self, response: requests.Response, previous_token: Any | None) -> Any | None:
offset = response.json().get('offset', 0)
if not offset:
return self.next_token()

total = response.json().get('total')
if not total or offset >= total:
return self.next_token()

if not self.page_size:
self.page_size = offset

self.__offset += self.page_size
return self.additional_params


class BreakdownsAnalyticsReportsSourcesStream(BreakdownsAnalyticsReportsBaseStream):
name = "analytics_reports_sources"
path = "analytics/v2/reports/sources/total"
d1_options = ['organic', 'referrals', 'social']


class BreakdownsAnalyticsReportsGeolocationStream(BreakdownsAnalyticsReportsBaseStream):
name = "analytics_reports_geolocation"
path = "analytics/v2/reports/geolocation/total"
d1_options = ['regions', 'us', 'organic', 'referrals', 'social', 'test']


class BreakdownsAnalyticsReportsUtmCampaignsStream(BreakdownsAnalyticsReportsBaseStream):
name = "analytics_reports_utm_campaigns"
path = "analytics/v2/reports/utm-campaigns/total"
d1_options = ['regions', 'us', 'organic', 'referrals', 'social', 'test']
class FormsSummaryMonthlyStream(hubspotV1Stream):
"""Association Base Stream"""
#https://legacydocs.hubspot.com/docs/methods/analytics/get-analytics-data-by-object
Expand Down
14 changes: 0 additions & 14 deletions tap_hubspot_beta/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@
AssociationTasksCompaniesStream,
AssociationTasksContactsStream,
AssociationTasksDealsStream,
SessionAnalyticsDailyReportsStream,
SessionAnalyticsWeeklyReportsStream,
SessionAnalyticsMonthlyReportsStream,
SessionAnalyticsTotalReportStream,
BreakdownsAnalyticsReportsSourcesStream,
BreakdownsAnalyticsReportsGeolocationStream,
BreakdownsAnalyticsReportsUtmCampaignsStream,
FormsSummaryMonthlyStream,
TeamsStream,
MeetingsAssociationStream,
Expand Down Expand Up @@ -159,13 +152,6 @@
AssociationTasksCompaniesStream,
AssociationTasksContactsStream,
AssociationTasksDealsStream,
SessionAnalyticsDailyReportsStream,
SessionAnalyticsWeeklyReportsStream,
SessionAnalyticsMonthlyReportsStream,
SessionAnalyticsTotalReportStream,
BreakdownsAnalyticsReportsSourcesStream,
BreakdownsAnalyticsReportsGeolocationStream,
BreakdownsAnalyticsReportsUtmCampaignsStream,
FormsSummaryMonthlyStream,
TeamsStream,
MeetingsAssociationStream,
Expand Down