0.0.20240519 • Published 1 day ago

@maxim_mazurok/gapi.client.analyticsdata-v1beta v0.0.20240519

Weekly downloads
-
License
MIT
Repository
github
Last release
1 day ago

TypeScript typings for Google Analytics Data API v1beta

Accesses report data in Google Analytics. Warning: Creating multiple Customer Applications, Accounts, or Projects to simulate or act as a single Customer Application, Account, or Project (respectively) or to circumvent Service-specific usage limits or quotas is a direct violation of Google Cloud Platform Terms of Service as well as Google APIs Terms of Service. These actions can result in immediate termination of your GCP project(s) without any warning. For detailed description please check documentation.

Installing

Install typings for Google Analytics Data API:

npm install @types/gapi.client.analyticsdata-v1beta --save-dev

Usage

You need to initialize Google API client in your code:

gapi.load('client', () => {
  // now we can use gapi.client
  // ...
});

Then load api client wrapper:

gapi.client.load(
  'https://analyticsdata.googleapis.com/$discovery/rest?version=v1beta',
  () => {
    // now we can use:
    // gapi.client.analyticsdata
  }
);
// Deprecated, use discovery document URL, see https://github.com/google/google-api-javascript-client/blob/master/docs/reference.md#----gapiclientloadname----version----callback--
gapi.client.load('analyticsdata', 'v1beta', () => {
  // now we can use:
  // gapi.client.analyticsdata
});

Don't forget to authenticate your client before sending any request to resources:

// declare client_id registered in Google Developers Console
var client_id = '',
  scope = [
    // View and manage your Google Analytics data
    'https://www.googleapis.com/auth/analytics',

    // See and download your Google Analytics data
    'https://www.googleapis.com/auth/analytics.readonly',
  ],
  immediate = true;
// ...

gapi.auth.authorize(
  {client_id: client_id, scope: scope, immediate: immediate},
  authResult => {
    if (authResult && !authResult.error) {
      /* handle successful authorization */
    } else {
      /* handle authorization error */
    }
  }
);

After that you can use Google Analytics Data API resources:

/*
Returns multiple pivot reports in a batch. All reports must be for the same GA4 Property.
*/
await gapi.client.analyticsdata.properties.batchRunPivotReports({
  property: 'property',
});

/*
Returns multiple reports in a batch. All reports must be for the same GA4 Property.
*/
await gapi.client.analyticsdata.properties.batchRunReports({
  property: 'property',
});

/*
This compatibility method lists dimensions and metrics that can be added to a report request and maintain compatibility. This method fails if the request's dimensions and metrics are incompatible. In Google Analytics, reports fail if they request incompatible dimensions and/or metrics; in that case, you will need to remove dimensions and/or metrics from the incompatible report until the report is compatible. The Realtime and Core reports have different compatibility rules. This method checks compatibility for Core reports.
*/
await gapi.client.analyticsdata.properties.checkCompatibility({
  property: 'property',
});

/*
Returns metadata for dimensions and metrics available in reporting methods. Used to explore the dimensions and metrics. In this method, a Google Analytics GA4 Property Identifier is specified in the request, and the metadata response includes Custom dimensions and metrics as well as Universal metadata. For example if a custom metric with parameter name `levels_unlocked` is registered to a property, the Metadata response will contain `customEvent:levels_unlocked`. Universal metadata are dimensions and metrics applicable to any property such as `country` and `totalUsers`.
*/
await gapi.client.analyticsdata.properties.getMetadata({name: 'name'});

/*
Returns a customized pivot report of your Google Analytics event data. Pivot reports are more advanced and expressive formats than regular reports. In a pivot report, dimensions are only visible if they are included in a pivot. Multiple pivots can be specified to further dissect your data.
*/
await gapi.client.analyticsdata.properties.runPivotReport({
  property: 'property',
});

/*
Returns a customized report of realtime event data for your property. Events appear in realtime reports seconds after they have been sent to the Google Analytics. Realtime reports show events and usage data for the periods of time ranging from the present moment to 30 minutes ago (up to 60 minutes for Google Analytics 360 properties). For a guide to constructing realtime requests & understanding responses, see [Creating a Realtime Report](https://developers.google.com/analytics/devguides/reporting/data/v1/realtime-basics).
*/
await gapi.client.analyticsdata.properties.runRealtimeReport({
  property: 'property',
});

/*
Returns a customized report of your Google Analytics event data. Reports contain statistics derived from data collected by the Google Analytics tracking code. The data returned from the API is as a table with columns for the requested dimensions and metrics. Metrics are individual measurements of user activity on your property, such as active users or event count. Dimensions break down metrics across some common criteria, such as country or event name. For a guide to constructing requests & understanding responses, see [Creating a Report](https://developers.google.com/analytics/devguides/reporting/data/v1/basics).
*/
await gapi.client.analyticsdata.properties.runReport({property: 'property'});
0.0.20240519

1 day ago

0.0.20240514

6 days ago

0.0.20240515

5 days ago

0.0.20240513

7 days ago

0.0.20240512

8 days ago

0.0.20240508

12 days ago

0.0.20240507

13 days ago

0.0.20240504

15 days ago

0.0.20240501

19 days ago

0.0.20240430

20 days ago

0.0.20240429

21 days ago

0.0.20240427

22 days ago

0.0.20240424

26 days ago

0.0.20240423

27 days ago

0.0.20240422

28 days ago

0.0.20240420

29 days ago

0.0.20240417

1 month ago

0.0.20240416

1 month ago

0.0.20240415

1 month ago

0.0.20240414

1 month ago

0.0.20240410

1 month ago

0.0.20240409

1 month ago

0.0.20240407

1 month ago

0.0.20240403

2 months ago

0.0.20240402

2 months ago

0.0.20240401

2 months ago

0.0.20240330

2 months ago

0.0.20240327

2 months ago

0.0.20240326

2 months ago

0.0.20240325

2 months ago

0.0.20240324

2 months ago

0.0.20240320

2 months ago

0.0.20240318

2 months ago

0.0.20240317

2 months ago

0.0.20240313

2 months ago

0.0.20240310

2 months ago

0.0.20240311

2 months ago

0.0.20240312

2 months ago

0.0.20240305

3 months ago

0.0.20240304

3 months ago

0.0.20240302

3 months ago

0.0.20240228

3 months ago

0.0.20240226

3 months ago

0.0.20240227

3 months ago

0.0.20240224

3 months ago

0.0.20240221

3 months ago

0.0.20240220

3 months ago

0.0.20240219

3 months ago

0.0.20240214

3 months ago

0.0.20240211

3 months ago

0.0.20240207

3 months ago

0.0.20240206

3 months ago

0.0.20240205

4 months ago

0.0.20240204

4 months ago

0.0.20240131

4 months ago

0.0.20240130

4 months ago

0.0.20240123

4 months ago

0.0.20240129

4 months ago

0.0.20240128

4 months ago

0.0.20240120

4 months ago

0.0.20240116

4 months ago

0.0.20240115

4 months ago

0.0.20240110

4 months ago

0.0.20240109

4 months ago

0.0.20240107

4 months ago

0.0.20240103

5 months ago

0.0.20240102

5 months ago

0.0.20231212

5 months ago

0.0.20231211

5 months ago

0.0.20231210

5 months ago

0.0.20231205

6 months ago

0.0.20231204

6 months ago

0.0.20231203

6 months ago

0.0.20231129

6 months ago

0.0.20230817

9 months ago

0.0.20231106

7 months ago

0.0.20231105

7 months ago

0.0.20231108

6 months ago

0.0.20231107

7 months ago

0.0.20230815

9 months ago

0.0.20230812

9 months ago

0.0.20231113

6 months ago

0.0.20231112

6 months ago

0.0.20231114

6 months ago

0.0.20230808

10 months ago

0.0.20230926

8 months ago

0.0.20230927

8 months ago

0.0.20230809

10 months ago

0.0.20230920

8 months ago

0.0.20230924

8 months ago

0.0.20230804

10 months ago

0.0.20230801

10 months ago

0.0.20231101

7 months ago

0.0.20230717

10 months ago

0.0.20230718

10 months ago

0.0.20231128

6 months ago

0.0.20230711

10 months ago

0.0.20231127

6 months ago

0.0.20230712

10 months ago

0.0.20231009

7 months ago

0.0.20230830

9 months ago

0.0.20231008

8 months ago

0.0.20230710

11 months ago

0.0.20230716

10 months ago

0.0.20231011

7 months ago

0.0.20231015

7 months ago

0.0.20230829

9 months ago

0.0.20230708

11 months ago

0.0.20230827

9 months ago

0.0.20230828

9 months ago

0.0.20230821

9 months ago

0.0.20230822

9 months ago

0.0.20230820

9 months ago

0.0.20230704

11 months ago

0.0.20230705

11 months ago

0.0.20230823

9 months ago

0.0.20231001

8 months ago

0.0.20231003

8 months ago

0.0.20231002

8 months ago

0.0.20231004

8 months ago

0.0.20231029

7 months ago

0.0.20230731

10 months ago

0.0.20231031

7 months ago

0.0.20231030

7 months ago

0.0.20230729

10 months ago

0.0.20231018

7 months ago

0.0.20230722

10 months ago

0.0.20231017

7 months ago

0.0.20230726

10 months ago

0.0.20230724

10 months ago

0.0.20230725

10 months ago

0.0.20231023

7 months ago

0.0.20231022

7 months ago

0.0.20231025

7 months ago

0.0.20231024

7 months ago

0.0.20230627

11 months ago

0.0.20230917

8 months ago

0.0.20230918

8 months ago

0.0.20230910

8 months ago

0.0.20230913

8 months ago

0.0.20230912

8 months ago

0.0.20230906

9 months ago

0.0.20230904

9 months ago

0.0.20230905

9 months ago

0.0.20230625

11 months ago

0.0.20230626

11 months ago

0.0.20230524

12 months ago

0.0.20230529

12 months ago

0.0.20230531

12 months ago

0.0.20230530

12 months ago

0.0.20230430

1 year ago

0.0.20230619

11 months ago

0.0.20230612

11 months ago

0.0.20230613

11 months ago

0.0.20230610

11 months ago

0.0.20230614

11 months ago

0.0.20230620

11 months ago

0.0.20230607

12 months ago

0.0.20230605

12 months ago

0.0.20230606

12 months ago

0.0.20230604

12 months ago

0.0.20230514

1 year ago

0.0.20230517

1 year ago

0.0.20230515

1 year ago

0.0.20230516

1 year ago

0.0.20230521

1 year ago

0.0.20230509

1 year ago

0.0.20230502

1 year ago

0.0.20230503

1 year ago

0.0.20230621

11 months ago

0.0.20230501

1 year ago

0.0.20230507

1 year ago

0.0.20230510

1 year ago

0.0.20230414

1 year ago

0.0.20230412

1 year ago

0.0.20230418

1 year ago

0.0.20230419

1 year ago

0.0.20230301

1 year ago

0.0.20230403

1 year ago

0.0.20230404

1 year ago

0.0.20230402

1 year ago

0.0.20230408

1 year ago

0.0.20230405

1 year ago

0.0.20230410

1 year ago

0.0.20230315

1 year ago

0.0.20230314

1 year ago

0.0.20230319

1 year ago

0.0.20230322

1 year ago

0.0.20230320

1 year ago

0.0.20230321

1 year ago

0.0.20230425

1 year ago

0.0.20230304

1 year ago

0.0.20230426

1 year ago

0.0.20230423

1 year ago

0.0.20230308

1 year ago

0.0.20230306

1 year ago

0.0.20230307

1 year ago

0.0.20230312

1 year ago

0.0.20230326

1 year ago

0.0.20230327

1 year ago

0.0.20230329

1 year ago

0.0.20230228

1 year ago

0.0.20230226

1 year ago

0.0.20230214

1 year ago

0.0.20230215

1 year ago

0.0.20230220

1 year ago

0.0.20230221

1 year ago

0.0.20230205

1 year ago

0.0.20230206

1 year ago

0.0.20230129

1 year ago

0.0.20230207

1 year ago

0.0.20230131

1 year ago

0.0.20230212

1 year ago

0.0.20230213

1 year ago

0.0.20230201

1 year ago

0.0.20221115

2 years ago

0.0.20221114

2 years ago

0.0.20221112

2 years ago

0.0.20221109

2 years ago

0.0.20230103

1 year ago

0.0.20221108

2 years ago

0.0.20221107

2 years ago

0.0.20221106

2 years ago

0.0.20221130

1 year ago

0.0.20230117

1 year ago

0.0.20230118

1 year ago

0.0.20230115

1 year ago

0.0.20221210

1 year ago

0.0.20230124

1 year ago

0.0.20230125

1 year ago

0.0.20221207

1 year ago

0.0.20230122

1 year ago

0.0.20221206

1 year ago

0.0.20221129

1 year ago

0.0.20230123

1 year ago

0.0.20221128

1 year ago

0.0.20230107

1 year ago

0.0.20221203

1 year ago

0.0.20230110

1 year ago

0.0.20230111

1 year ago

0.0.20221031

2 years ago

0.0.20221016

2 years ago

0.0.20221012

2 years ago

0.0.20221011

2 years ago

0.0.20221010

2 years ago

0.0.20221009

2 years ago

0.0.20221029

2 years ago

0.0.20221026

2 years ago

0.0.20221004

2 years ago

0.0.20221102

2 years ago

0.0.20221003

2 years ago

0.0.20221101

2 years ago

0.0.20221024

2 years ago

0.0.20221002

2 years ago

0.0.20221023

2 years ago

0.0.20220927

2 years ago

0.0.20220928

2 years ago

0.0.20221019

2 years ago

0.0.20221018

2 years ago

0.0.20220926

2 years ago

0.0.20220830

2 years ago

0.0.20220917

2 years ago

0.0.20220907

2 years ago

0.0.20220819

2 years ago

0.0.20220831

2 years ago

0.0.20220920

2 years ago

0.0.20220910

2 years ago

0.0.20220822

2 years ago

0.0.20220913

2 years ago

0.0.20220825

2 years ago

0.0.20220925

2 years ago

0.0.20220914

2 years ago

0.0.20220904

2 years ago

0.0.20220817

2 years ago

0.0.20220816

2 years ago

0.0.20220813

2 years ago

0.0.20220810

2 years ago