Jihen BENMUSTAPHA
Jihen BENMUSTAPHA

Reputation: 11

trying to obtain number of visitors using gapi deprecated

I want to display number of visits of my website using google analytics so do that I need to do authentication by google .. it seams that gAPI is no longer used and this is what I get ..

{"error":"idpiframe_initialization_failed","details":"You have created a new client application that uses libraries for user authentication or authorization that are deprecated. New clients must use the new libraries instead. See the Migration Guide for more information."}..

I'm using angular 15 and this is my code

initGoogleOAuth() {
        const { clientId, apiKey } = environment.googleAnalytics;
    gapi.client.init({
          'apiKey': apiKey,
          'discoveryDocs': ['https://analyticsdata.googleapis.com/$discovery/rest?version=v1beta'],
          'clientId': clientId,
          'scope': 'https://www.googleapis.com/auth/analytics.readonly',
         }).then(() => {
          console.log('test')
          this.getAnalyticsData('2023-01-01','today')
        }).then(function (response:any) {
          console.log(response.result);
        }, function (reason:any) {
          console.log('Error: ' + JSON.stringify(reason));
        });
      }

I want to be able to retrieve the number of visitors of my website so what I can use instead of gAPI.

Upvotes: 0

Views: 177

Answers (1)

Shila Mosammami
Shila Mosammami

Reputation: 1077

As you have mentioned in your tags you need to activate Google Analytics for your website. From 1th July 2023 Universal Analytics is not going to work so you should use Goolge Analytics4 or GA4. Have a look at Google Analytics 4 Documentation and follow the instructions.

Upvotes: 0

Related Questions