we are moved to GA4 and now i'm trying to get data from GA4, but i cant move some part of code
$filters = ['dimensions' => 'ga:transactionId,ga:deviceCategory,ga:channelGrouping'];
if (is_array($orderIds)) {
$orderCollection = $this->orderCollectionFactory->create();
$orderCollection->addFieldToFilter('entity_id', ['in' => $orderIds]);
$startDate = $this->getStartDateFilter($orderCollection);
$filters = $this->getMetricsFilter($orderCollection);
}
$data = $this->_analytics->data_ga->get(
'ga:' . $profileId,
$startDate,
'today',
'ga:transactions',
$filters
);
What i have done now
* Set our property ID
*/
$propertyId = 'XXXXXX';
/**
* TODO(developer): Replace this variable with your Google Analytics 4
* property ID before running the sample.
*/
// Using a default constructor instructs the client to use the credentials
// specified in GOOGLE_APPLICATION_CREDENTIALS environment variable.
$client = new BetaAnalyticsDataClient();
// Make an API call.
$request = (new RunReportRequest())
->setProperty('properties/' . $propertyId)
->setDateRanges([
new DateRange([
'start_date' => '2023-10-31',
'end_date' => 'today',
]),
])
->setDimensionFilter(new FilterExpression())
->setDimensions([
new Dimension([
'name' => 'transactionId',
]),
new Dimension([
'name' => 'deviceCategory',
]),
new Dimension([
'name' => 'sessionDefaultChannelGrouping',
])
]);
$response = $client->runReport($request);
Maybe somebody know what i should do to get the same information ?
Rewrite previous code and check GA4 documentation