Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

docs: add sample code for Data API v1 #57

Merged
merged 42 commits into from Apr 6, 2021

Conversation

ikuleshov
Copy link
Collaborator

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@product-auto-label product-auto-label bot added api: analyticsdata Issues related to the googleapis/python-analytics-data API. samples Issues that are directly related to samples. labels Mar 25, 2021
@snippet-bot
Copy link

snippet-bot bot commented Mar 25, 2021

Here is the summary of possible violations 😱

There are 32 possible violations for not having product prefix.

The end of the violation section. All the stuff below is FYI purposes only.


Here is the summary of changes.

You are about to add 32 region tags.
You are about to delete 2 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 25, 2021
@ikuleshov ikuleshov added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 31, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 31, 2021
@ikuleshov ikuleshov marked this pull request as ready for review April 2, 2021 20:49
@ikuleshov ikuleshov requested review from a team as code owners April 2, 2021 20:49
@ikuleshov ikuleshov requested review from kurtisvg and removed request for a team April 2, 2021 20:49
@ikuleshov
Copy link
Collaborator Author

Apologies for a large PR, but samples are quite repetitive: just different variations of the Data API reporting queries.

@ikuleshov
Copy link
Collaborator Author

Please let me know if splitting a PR would help a review, though.

property, including custom fields."""
client = BetaAnalyticsDataClient()

# [START analyticsdata_get_metadata_by_property_id]
Copy link

Choose a reason for hiding this comment

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

Regions tags should show enough the user can copy/paste them to run, including imports - see "Region Tags" in the authoring guide.

It's also generally preferred to have 1 snippet per file.

Copy link

Choose a reason for hiding this comment

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

(same everywhere)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Kurtis, we do follow this advice for quickstart samples. However, other snippets are included in the API usage guides that demonstrate the usage of various API features inside one document (e.g. "Advanced API Features Guide", "Migration Guide"). It is therefore useful to include just the relevant part of the snippet to illustrate the feature. If a user wants to see the complete example, they can follow a link to GitHub.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here is an example of the guide we will need to include the samples into:
https://developers.devsite.corp.google.com/analytics/devguides/reporting/data/v1/basics

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, I grouped certain samples together in one file since they demonstrate the same concept (e.g. run_report_with_filters.py), just with different queries. Creating a separate file for each sample looks a bit redundant here, though we may consider separating these in the future. The more use cases we demonstrate, the easier it will be for the users to adopt the API...

Copy link

Choose a reason for hiding this comment

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

Yes, we should do it for each sample. The goal is that samples should be "copy-paste-runnable" - most users want to be able to copy a sample, paste it into their own environment, and run it immediately with only minor changes. This is what the sample format is optimizing for.

It may seem redundant but having each sample isolated into its own file makes it easier to ensure only used imports are included and that each snippet make sense without additional context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree this makes sense. I moved each sample into a separate file and moved region tags around to include the entire sample.

samples/snippets/get_metadata.py Outdated Show resolved Hide resolved
samples/snippets/get_metadata.py Outdated Show resolved Hide resolved
samples/snippets/get_metadata.py Outdated Show resolved Hide resolved
Dimension(name="city"),
],
metrics=[Metric(name="activeUsers")],
date_ranges=[DateRange(start_date="7daysAgo", end_date="today")],
Copy link

Choose a reason for hiding this comment

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

Can you add a link to some documentation around what format these should be?

Copy link

Choose a reason for hiding this comment

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

It would good if anywhere there is a "magic string" or value that the user need to customize themselves there is a comment reflecting that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I replaced magic strings with absolute values in order not to distract the attention from the main point of the sample: batch requests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Once we have the guides published, I'll update the description for each sample with a link to the relevant portion of the guide, which should also address the magic strings issue.

Copy link

Choose a reason for hiding this comment

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

Feels like there are still an awful lot of values that make no sense to me as someone trying to learn the API. Is there no reference documentation we can refer them to before the guide is published?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a link to the reference doc for every sample. Might replace this with a link to the corresponding guide document once it is published.

samples/snippets/run_realtime_report_test.py Outdated Show resolved Hide resolved
Copy link

@kurtisvg kurtisvg left a comment

Choose a reason for hiding this comment

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

oops - hit the wrong button. See the comments in the last review.

property, including custom fields."""
client = BetaAnalyticsDataClient()

# [START analyticsdata_get_metadata_by_property_id]
Copy link

Choose a reason for hiding this comment

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

Yes, we should do it for each sample. The goal is that samples should be "copy-paste-runnable" - most users want to be able to copy a sample, paste it into their own environment, and run it immediately with only minor changes. This is what the sample format is optimizing for.

It may seem redundant but having each sample isolated into its own file makes it easier to ensure only used imports are included and that each snippet make sense without additional context.

samples/snippets/get_metadata_test.py Outdated Show resolved Hide resolved
samples/snippets/run_realtime_report_test.py Outdated Show resolved Hide resolved
property="properties/" + str(property_id),
dimensions=[Dimension(name="browser")],
metrics=[Metric(name="activeUsers")],
date_ranges=[DateRange(start_date="7daysAgo", end_date="yesterday")],
Copy link

Choose a reason for hiding this comment

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

nit: Missed a date range update

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a link to the date range reference documentation instead.


def print_get_metadata_response(response):
"""Prints results of the getMetadata call."""
# [START analyticsdata_print_get_metadata_response]
Copy link

Choose a reason for hiding this comment

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

nit: Do you still want this region tag here if the wider one includes this section?


def print_run_pivot_report_response(response):
"""Prints results of a runPivotReport call."""
# [START analyticsdata_print_run_pivot_report_response]
Copy link

Choose a reason for hiding this comment

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

nit: Same w/ these region tags

@ikuleshov ikuleshov merged commit a1e63c5 into googleapis:master Apr 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: analyticsdata Issues related to the googleapis/python-analytics-data API. cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants