[Datasources] Add: simple Google Analytics query runner#1405
Merged
arikfr merged 6 commits intogetredash:masterfrom Nov 24, 2016
denisov-vlad:google_analytics
Merged
[Datasources] Add: simple Google Analytics query runner#1405arikfr merged 6 commits intogetredash:masterfrom denisov-vlad:google_analytics
arikfr merged 6 commits intogetredash:masterfrom
denisov-vlad:google_analytics
Conversation
arikfr
reviewed
Nov 22, 2016
| 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) |
|
|
||
| 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) |
Member
There was a problem hiding this comment.
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: |
Member
Author
There was a problem hiding this comment.
There's only one TYPE_DATETIME column on it has 10 chars length. So I can add raise Exception if length is different.
arikfr
requested changes
Nov 24, 2016
Member
arikfr
left a comment
There was a problem hiding this comment.
Looks good, two small changes and it's good to go :-)
| logger = logging.getLogger(__name__) | ||
|
|
||
| try: | ||
| import gspread |
| elif len(value) == 12: | ||
| value = datetime.strptime(value, '%Y%m%d%H%M') | ||
| else: | ||
| raise Exception('Wrong datetime format') |
Member
There was a problem hiding this comment.
Let's make it more friendly: "Unknown date/time format in results: '{}'".format(value).
arikfr
approved these changes
Nov 24, 2016
Member
|
👍 thanks for the quick follow up. |
dairyo
pushed a commit
to KiiCorp/redash
that referenced
this pull request
Mar 1, 2019
[Datasources] Add: simple Google Analytics query runner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To get data via this query runner you should copy&paste url from
API Query URIfield 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