Example #1
0
 /// <summary>Snippet for RunReport</summary>
 public void RunReportRequestObject()
 {
     // Snippet: RunReport(RunReportRequest, CallSettings)
     // Create client
     BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.Create();
     // Initialize request argument(s)
     RunReportRequest request = new RunReportRequest
     {
         Property           = "",
         Dimensions         = { new Dimension(), },
         Metrics            = { new Metric(), },
         DateRanges         = { new DateRange(), },
         DimensionFilter    = new FilterExpression(),
         MetricFilter       = new FilterExpression(),
         Offset             = 0L,
         Limit              = 0L,
         MetricAggregations =
         {
             MetricAggregation.Unspecified,
         },
         OrderBys            = { new OrderBy(), },
         CurrencyCode        = "",
         CohortSpec          = new CohortSpec(),
         KeepEmptyRows       = false,
         ReturnPropertyQuota = false,
     };
     // Make the request
     RunReportResponse response = betaAnalyticsDataClient.RunReport(request);
     // End snippet
 }
        static void SampleRunReport(string propertyId = "YOUR-GA4-PROPERTY-ID")
        {
            /**
             * TODO(developer): Uncomment this variable and replace with your
             *  Google Analytics 4 property ID before running the sample.
             */
            // propertyId = "YOUR-GA4-PROPERTY-ID";

            // [START analyticsdata_initialize]
            // Using a default constructor instructs the client to use the credentials
            // specified in GOOGLE_APPLICATION_CREDENTIALS environment variable.
            BetaAnalyticsDataClient client = BetaAnalyticsDataClient.Create();
            // [END analyticsdata_initialize]

            // [START analyticsdata_run_report]
            // Initialize request argument(s)
            RunReportRequest request = new RunReportRequest
            {
                Property   = "properties/" + propertyId,
                Dimensions = { new Dimension {
                                   Name = "city"
                               }, },
                Metrics = { new Metric {
                                Name = "activeUsers"
                            }, },
                DateRanges = { new DateRange {
                                   StartDate = "2020-03-31", EndDate = "today"
                               }, },
            };

            // Make the request
            var response = client.RunReport(request);

            // [END analyticsdata_run_report]

            // [START analyticsdata_run_report_response]
            Console.WriteLine("Report result:");
            foreach (Row row in response.Rows)
            {
                Console.WriteLine("{0}, {1}", row.DimensionValues[0].Value, row.MetricValues[0].Value);
            }
            // [END analyticsdata_run_report_response]
        }
Example #3
0
        /// <summary>Snippet for RunReport</summary>
        public void RunReportRequestObject()
        {
            // Snippet: RunReport(RunReportRequest, CallSettings)
            // Create client
            BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.Create();
            // Initialize request argument(s)
            RunReportRequest request = new RunReportRequest
            {
                Property           = "",
                Dimensions         = { new Dimension(), },
                Metrics            = { new Metric(), },
                DateRanges         = { new DateRange(), },
                DimensionFilter    = new FilterExpression(),
                MetricFilter       = new FilterExpression(),
                MetricAggregations =
                {
                    MetricAggregation.Unspecified,
                },
                OrderBys            = { new OrderBy(), },
                CurrencyCode        = "",
                CohortSpec          = new CohortSpec(),
                KeepEmptyRows       = false,
                ReturnPropertyQuota = false,
            };
            // Make the request
            PagedEnumerable <RunReportResponse, DimensionHeader> response = betaAnalyticsDataClient.RunReport(request);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (DimensionHeader item in response)
            {
                // Do something with each item
                Console.WriteLine(item);
            }

            // Or iterate over pages (of server-defined size), performing one RPC per page
            foreach (RunReportResponse page in response.AsRawResponses())
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (DimensionHeader item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            }

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int pageSize = 10;
            Page <DimensionHeader> singlePage = response.ReadPage(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (DimensionHeader item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }