Skip to content

[ENH] Add ability to enforce specific filter on Google Analytics query #8806

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

Closed
wants to merge 1 commit into from
Closed
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: 8 additions & 4 deletions pandas/io/ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from oauth2client.client import AccessTokenRefreshError
from pandas.compat import zip, u


TYPE_MAP = {u('INTEGER'): int, u('FLOAT'): float, u('TIME'): int}

NO_CALLBACK = auth.OOB_CALLBACK_URN
Expand Down Expand Up @@ -251,7 +252,7 @@ def get_data(self, metrics, start_date, end_date=None,
converters=None, sort=True, dayfirst=False,
account_name=None, account_id=None, property_name=None,
property_id=None, profile_name=None, profile_id=None,
chunksize=None):
chunksize=None, raw_filters=False):
if chunksize is None and max_results > 10000:
raise ValueError('Google API returns maximum of 10,000 rows, '
'please set chunksize')
Expand All @@ -274,8 +275,7 @@ def _read(start, result_size):
end_date=end_date, dimensions=dimensions,
segment=segment, filters=filters,
start_index=start,
max_results=result_size)

max_results=result_size, raw_filters=raw_filters)
try:
rs = query.execute()
rows = rs.get('rows', [])
Expand Down Expand Up @@ -332,6 +332,7 @@ def create_query(self, profile_id, metrics, start_date, end_date=None,
dimensions=dimensions, segment=segment,
filters=filters, start_index=start_index,
max_results=max_results, **kwargs)
print("QUERY\n{}".format(qry))
try:
return self.service.data().ga().get(**qry)
except TypeError as error:
Expand Down Expand Up @@ -376,8 +377,11 @@ def format_query(ids, metrics, start_date, end_date=None, dimensions=None,
if max_results is not None:
qry['max_results'] = str(max_results)

return qry
if kwargs['raw_filters'] == True:
qry['filters'] = filters
del qry['raw_filters']

return qry

def _maybe_add_arg(query, field, data, prefix='ga'):
if data is not None:
Expand Down