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

[Datasources] Add: simple Google Analytics query runner #1405

Merged
merged 6 commits into from
Nov 24, 2016
Merged

[Datasources] Add: simple Google Analytics query runner #1405

merged 6 commits into from
Nov 24, 2016

Conversation

denisov-vlad
Copy link
Member

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

@arikfr arikfr changed the title simple GA query runner Add: simple Google Analytics query runner Nov 17, 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)
Copy link
Member

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)
Copy link
Member

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and if not?

Copy link
Member Author

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.

@arikfr arikfr changed the title Add: simple Google Analytics query runner [Datasources] Add: simple Google Analytics query runner Nov 24, 2016
Copy link
Member

@arikfr arikfr left a 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
Copy link
Member

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')
Copy link
Member

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).

@arikfr arikfr merged commit 47c1ac8 into getredash:master Nov 24, 2016
@arikfr
Copy link
Member

arikfr commented Nov 24, 2016

👍 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants