Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
551 views
in Technique[技术] by (71.8m points)

javascript - Google Analytics Data API (GA4) How to use runRealtimeReport function?

I do a call to

await analyticsDataClient.runRealtimeReport({
      entity: {
        propertyId: propertyId,
      },
      dateRanges: [
        {
          startDate: '2020-03-31',
          endDate: 'today',
        },
      ],
      dimensions: [
        {
          name: 'city',
        },
      ],
      metrics: [
        {
          name: 'activeUsers',
        },
      ],
    });

but this return the following error:

A property in the form 'properties/1234' where '1234' is a GA4 property Id is required

I think it is because my object inside my runRealtimeReport function is wrong but I don't know how to put in.

question from:https://stackoverflow.com/questions/65913387/google-analytics-data-api-ga4-how-to-use-runrealtimereport-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To create a realtime report, you need to update the request to be similar to

  const propertyId = 'YOUR-GA4-PROPERTY-ID';
  const [response] = await client.runRealtimeReport({
    property: 'properties/' + propertyId,
    dimensions: [{ name: 'city', },],
    metrics: [{ name: 'activeUsers', },],
  });

Please replace the 'YOUR-GA4-PROPERTY-ID' with your numeric property ID. This page describes where to find your GA4 property ID.

Realtime reports do not need dateRanges. Realtime reports are always for the last 30 minutes for your App or Website. There is more information about creating realtime reports on this page.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...