Skip to content

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

Merged
arikfr merged 6 commits intogetredash:masterfrom
denisov-vlad:google_analytics
Nov 24, 2016
Merged

[Datasources] Add: simple Google Analytics query runner#1405
arikfr merged 6 commits intogetredash:masterfrom
denisov-vlad:google_analytics

Conversation

@denisov-vlad
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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