Why doesn't this combination of dimensions and metrics bring me results?
When adding dimension_filter by regular expression it no longer generates results, is that combination possible?
I need to generate a report of page views and total users by date on a certain page.
Could you explain to me in a descriptive way if it is possible what I am trying to obtain?
<?php
$propertyId = '123456789';
putenv('GOOGLE_APPLICATION_CREDENTIALS=343adgb34344.json');
$dateRangeStart = date('Y-m-d', strtotime('-46 days'));
$valueRegex = '\/([a-z]|[0-9]|-)*\/([a-z]|[0-9]|-)*\/([a-z]|[0-9]|-)*-2203644$';
run_batch_report($propertyId, $dateRangeStart, $valueRegex);
function run_batch_report(string $propertyId, $dateRangeStart, $valueRegex)
{
// Create an instance of the Google Analytics Data API client library.
$client = new BetaAnalyticsDataClient();
// Make an API call.
$request = (new BatchRunReportsRequest())
->setProperty('properties/' . $propertyId)
->setRequests([
new RunReportRequest([
'dimensions' => [
new Dimension(['name' => 'date'])
],
'metrics' => [
new Metric(['name' => 'totalUsers']),
new Metric(['name' => 'screenPageViews'])
],
'date_ranges' => [new DateRange([
'start_date' => $dateRangeStart,
'end_date' => 'today',
])],
'dimension_filter' => new FilterExpression([
'filter' => new Filter([
'field_name' => 'pagePathPlusQueryString',
'string_filter' => new Filter\StringFilter([
'match_type' => Filter\StringFilter\MatchType::FULL_REGEXP,
'value' => $valueRegex
])
])
])
]),
]);
$response = $client->batchRunReports($request);
$result = $response->serializeToJsonString();
print_r($result);
exit;
}