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

Commit

Permalink
Browse files Browse the repository at this point in the history
docs: update region tag names to match the convention (#55)
* docs: update region tag names to match the convention

* lint
  • Loading branch information
ikuleshov committed Mar 25, 2021
1 parent 4551e99 commit 747f551
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
16 changes: 8 additions & 8 deletions samples/snippets/quickstart.py
Expand Up @@ -26,7 +26,7 @@
pip3 install --upgrade google-analytics-data
python3 quickstart.py
"""
# [START google_analytics_data_quickstart]
# [START analyticsdata_quickstart]
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import DateRange
from google.analytics.data_v1beta.types import Dimension
Expand All @@ -40,30 +40,30 @@ def sample_run_report(property_id="YOUR-GA4-PROPERTY-ID"):
# Google Analytics 4 property ID before running the sample.
# property_id = "YOUR-GA4-PROPERTY-ID"

# [START google_analytics_data_initialize]
# [START analyticsdata_run_report_initialize]
# Using a default constructor instructs the client to use the credentials
# specified in GOOGLE_APPLICATION_CREDENTIALS environment variable.
client = BetaAnalyticsDataClient()
# [END google_analytics_data_initialize]
# [END analyticsdata_run_report_initialize]

# [START google_analytics_data_run_report]
# [START analyticsdata_run_report]
request = RunReportRequest(
property="properties/" + str(property_id),
dimensions=[Dimension(name="city")],
metrics=[Metric(name="activeUsers")],
date_ranges=[DateRange(start_date="2020-03-31", end_date="today")],
)
response = client.run_report(request)
# [END google_analytics_data_run_report]
# [END analyticsdata_run_report]

# [START google_analytics_data_run_report_response]
# [START analyticsdata_run_report_response]
print("Report result:")
for row in response.rows:
print(row.dimension_values[0].value, row.metric_values[0].value)
# [END google_analytics_data_run_report_response]
# [END analyticsdata_run_report_response]


# [END google_analytics_data_quickstart]
# [END analyticsdata_quickstart]


if __name__ == "__main__":
Expand Down
14 changes: 8 additions & 6 deletions samples/snippets/quickstart_json_credentials.py
Expand Up @@ -27,7 +27,7 @@
pip3 install --upgrade google-analytics-data
python3 quickstart_json_credentials.py
"""
# [START google_analytics_data_quickstart]
# [START analyticsdata_json_credentials_quickstart]
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import DateRange
from google.analytics.data_v1beta.types import Dimension
Expand All @@ -41,7 +41,7 @@ def sample_run_report(property_id="YOUR-GA4-PROPERTY-ID", credentials_json_path=
# Google Analytics 4 property ID before running the sample.
# property_id = "YOUR-GA4-PROPERTY-ID"

# [START google_analytics_data_initialize]
# [START analyticsdata_json_credentials_initialize]
# TODO(developer): Uncomment this variable and replace with a valid path to
# the credentials.json file for your service account downloaded from the
# Cloud Console.
Expand All @@ -50,22 +50,24 @@ def sample_run_report(property_id="YOUR-GA4-PROPERTY-ID", credentials_json_path=
# Explicitly use service account credentials by specifying
# the private key file.
client = BetaAnalyticsDataClient().from_service_account_json(credentials_json_path)
# [END google_analytics_data_initialize]
# [END analyticsdata_json_credentials_initialize]

# [START google_analytics_data_run_report]
# [START analyticsdata_json_credentials_run_report]
request = RunReportRequest(
property="properties/" + str(property_id),
dimensions=[Dimension(name="city")],
metrics=[Metric(name="activeUsers")],
date_ranges=[DateRange(start_date="2020-03-31", end_date="today")],
)
response = client.run_report(request)
# [END google_analytics_data_run_report]
# [END analyticsdata_json_credentials_run_report]

print("Report result:")
for row in response.rows:
print(row.dimension_values[0].value, row.metric_values[0].value)
# [END google_analytics_data_quickstart]


# [END analyticsdata_json_credentials_quickstart]


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions samples/snippets/quickstart_oauth2.py
Expand Up @@ -27,7 +27,7 @@
pip3 install --upgrade google-analytics-data
python3 quickstart_oauth2.py
"""
# [START google_analytics_data_quickstart]
# [START analyticsdata_quickstart_oauth2]
from google.analytics.data import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import DateRange
from google.analytics.data_v1beta.types import Dimension
Expand Down Expand Up @@ -59,7 +59,7 @@ def sample_run_report(credentials=None, property_id="YOUR-GA4-PROPERTY-ID"):

def get_credentials():
"""Creates an OAuth2 credentials instance."""
# [START google_analytics_data_initialize]
# [START analyticsdata_initialize]
appflow = flow.InstalledAppFlow.from_client_secrets_file(
"client_secrets.json",
scopes=["https://www.googleapis.com/auth/analytics.readonly"],
Expand All @@ -75,15 +75,15 @@ def get_credentials():
else:
appflow.run_console()
return appflow.credentials
# [END google_analytics_data_initialize]
# [END analyticsdata_initialize]


def main():
credentials = get_credentials()
sample_run_report(credentials)


# [END google_analytics_data_quickstart]
# [END analyticsdata_quickstart_oauth2]

if __name__ == "__main__":
main()

0 comments on commit 747f551

Please sign in to comment.