AJ.hassy
AJ.hassy

Reputation: 135

Data API PHP Client library Multiple Metrics

Can I request multiple Metrics using the Data API PHP client library?

ex) date for dimension, sessions and totalUsers for metric for Data API request

Upvotes: 1

Views: 303

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116968

Sure why not? Metrics is just an array same as dimensions.

$response = $client->runReport([
    'property' => 'properties/' . $property_id,
    'dateRanges' => [
        new DateRange([
            'start_date' => '2020-03-31',
            'end_date' => 'today',
        ]),
    ],
    'dimensions' => [new Dimension(
        [
            'name' => 'date',
        ]
    ),
    ],
    'metrics' => [new Metric(
        [
            'name' => 'sessions',
        ]
    ),new Metric(
        [
            'name' => 'totalUsers',
        ]
    )
    ]
]);

API Quickstar

Upvotes: 1

Related Questions