-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
[Datasources] Add: simple Google Analytics query runner #1405
Conversation
return build('analytics', 'v3', http=credentials.authorize(httplib2.Http())) | ||
|
||
def run_query(self, query, user): | ||
logger.info("Analytics is about to execute query: %s", query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.debug
|
||
def run_query(self, query, user): | ||
logger.info("Analytics is about to execute query: %s", query) | ||
params = parse_qs(urlparse(query).query, keep_blank_values=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we expect a JSON object instead of a query string? It will make parsing simpler, but also less error prone (most users won't know how to properly escape the query string).
if column_type == TYPE_DATE: | ||
value = datetime.strptime(value, '%Y%m%d') | ||
elif column_type == TYPE_DATETIME: | ||
if len(value) == 10: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and if not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only one TYPE_DATETIME column on it has 10 chars length. So I can add raise Exception if length is different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, two small changes and it's good to go :-)
logger = logging.getLogger(__name__) | ||
|
||
try: | ||
import gspread |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need gspread here.
elif len(value) == 12: | ||
value = datetime.strptime(value, '%Y%m%d%H%M') | ||
else: | ||
raise Exception('Wrong datetime format') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it more friendly: "Unknown date/time format in results: '{}'".format(value)
.
👍 thanks for the quick follow up. |
[Datasources] Add: simple Google Analytics query runner
To get data via this query runner you should copy&paste url from
API Query URI
field on this page: https://ga-dev-tools.appspot.com/query-explorer/for example:
https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A84987497&start-date=2016-09-01&end-date=2016-09-30&metrics=ga%3AnewUsers&dimensions=ga%3AsubContinent&filters=ga%3AsubContinent%3D%3DAustralasia&samplingLevel=HIGHER_PRECISION&max-results=100