-
How to retrieve report data from Google Analytics 4 (GA4)
Hey folks! Just wondering, has anyone else been using
@google-analytics/data
to pull data from Google Analytics? It’s looking good so far in the example from the library. But here’s the thing – it’s still in BETA. Does that make anyone nervous? Like, could it flip out on me at any moment? ‘Cause that’s what I’m thinking!Here’s a snippet from the official example:
/** * TODO(developer): Uncomment this variable and replace with your * Google Analytics 4 property ID before running the sample. */ // propertyId = 'YOUR-GA4-PROPERTY-ID'; // Imports the Google Analytics Data API client library. const {BetaAnalyticsDataClient} = require('@google-analytics/data'); // Using a default constructor instructs the client to use the credentials // specified in GOOGLE_APPLICATION_CREDENTIALS environment variable. const analyticsDataClient = new BetaAnalyticsDataClient(); // Runs a simple report. async function runReport() { const [response] = await analyticsDataClient.runReport({ property:
properties/<span class="hljs-subst">${propertyId}</span>
, dateRanges: [ { startDate: '2020-03-31', endDate: 'today', }, ], dimensions: [ { name: 'city', }, ], metrics: [ { name: 'activeUsers', }, ], }); console.log('Report result:'); response.rows.forEach(row => { console.log(row.dimensionValues[0], row.metricValues[0]); }); } runReport();I was able to get this up and running in my app, and it’s doing its thing perfectly. But yeah, the BETA label is worrying me a bit. Anyone got an alternative in case this one blows up on me? Much appreciated!
Log in to reply.