This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
run_report_with_custom_parameters.py
41 lines (33 loc) · 1.49 KB
/
run_report_with_custom_parameters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# Copyright 2021 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Google Analytics Data API sample application.
"""
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import RunReportRequest
def run_report_with_custom_parameters(property_id="YOUR-GA4-PROPERTY-ID"):
"""Runs a simple report on a Google Analytics 4 property."""
client = BetaAnalyticsDataClient()
# [START run_report_with_custom_parameters]
request = RunReportRequest()
response = client.run_report(request)
# [END run_report_with_custom_parameters]
print("Report result:")
for row in response.rows:
print(row.dimension_values[0].value, row.metric_values[0].value)
if __name__ == "__main__":
# TODO(developer): Replace this variable with your Google Analytics 4
# property ID before running the sample.
property_id = "YOUR-GA4-PROPERTY-ID"
run_report_with_custom_parameters(property_id)