1

I'm able to successfully connect to Google Analytics(GA4) but I'm receiving an empty array for properties even though my Google Analytics account is an administrator for two properties in conjunction with the service account I am using for authentication. The response I am getting is "Google analytics connection is working and your account is: markusets Available properties: []". I am using the v3 version of the API, I'm looking for a solution to be able to retrieve the available properties.

When I run this NodeJs script:

const { google } = require("googleapis");
const analytics = google.analytics("v3");
const credentials = require("./service-account-credentials.json");

const client = new google.auth.JWT(
  credentials.client_email,
  null,
  credentials.private_key,
  ["https://www.googleapis.com/auth/analytics.readonly"]
);

client.authorize((err) => {
  if (err) {
    console.log(err);
    return;
  }
  //call to get account name
  analytics.management.accounts.list({ auth: client }, (err, result) => {
    if (err) {
      console.log(err);
    } else {
      console.log(
        `Google analytics connection is working and your account is: ${result.data.items[0].name}`
      );
      //call to get properties
      analytics.management.webproperties.list(
        {
          auth: client,
          accountId: "12345678",
        },
        (err, result) => {
          if (err) {
            console.log(err);
          } else {
            console.log(
              `Available properties: ${JSON.stringify(result.data.items)}`
            );
          }
        }
      );
    }
  });
});

I get:

Google analytics connection is working and your account is: markusets
Available properties: []

So what I've tried so far is to retrieve the available properties of my Google Analytics account using a service account and the Google Analytics API (v3). I have verified that my account and the service account have administrator privileges for the properties and that the credentials are correct because I am receiving the message "Google analytics connection is working and your account is: markusets" which suggests that I have been successfully authenticated. However, when I try to retrieve the properties, the resulting array is empty. I have tried different methods to retrieve the properties but none of them have worked so far. I am looking for a solution or a reason why the properties array is empty despite the correct authentication.

1 Answer 1

1

The Google Analytics Management API only allows you to access Universal Analytics properties. If you want to list your GA4 properties, you'll need to use the (still in Alpha/Beta) Google Analytics Admin API.

Not the answer you're looking for? Browse other questions tagged or ask your own question.