(Original title: Following the README: json key is missing the type field.)

Problem/Motivation

Following the README file steps at: https://git.drupalcode.org/project/google_analytics_reports/-/blob/4.0.x/README.md when you try to upload your downloaded JSON file, you'd get an error:

There was an authentication error. Message: json key is missing the type field.

CommentFileSizeAuthor
#5 GAReports-getKey.png42.68 KBmegan_m
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

doxigo created an issue. See original summary.

Toluwanimi’s picture

I'm having the same issue here. Any help?

marco.aresu’s picture

The Readme is wrong.
In the "Create credentials" menu, you must use "Service account", not "Help me choose".
Select the "Service account" created and generate a new JSON key.

Add the "Service account" email as user in the Google Analytics G4 property.

Remember, use the Google Analytics G4 Property ID.

alabandit’s picture

I'm having no luck with the

  1. README,
  2. #3 Service account
  3. or the solution in the interface:
    Add a credential and put json file here https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart-client-libraries#step_2_add_service_account_to_the_google_analytics_4_property

I am just missing the obvious?

All I get from all is:

    There was an authentication error. Message: Could not construct ApplicationDefaultCredentials.
    Credential is not valid. Check your configured property also!
megan_m’s picture

StatusFileSize
new42.68 KB

The instructions from the link don't work either. It doesn't give you the credentials file that you want, although Step 2 is right. What you want is a credentials file in json format with a file name like your-property-name-[string of numbers].json.

When I set this up in developers.google I followed the instructions in the Readme and it did generate a service account. From API/service details, look for Service Accounts. Then edit that, and use the Keys tab to create a new key. This will let you generate the json file.

Screenshot showing how to find the Keys tab

That will let you download a json file. That's what you need to upload in the module settings.

Then, as marco mentioned in #3, you need to add that email address as a user in GA4. From GA4, go to Admin then look for Account access management.

kurttrowbridge made their first commit to this issue’s fork.

kurttrowbridge’s picture

Title: Following the README: json key is missing the type field. » Update setup documentation for improved accuracy
Version: 4.0.0-alpha1 » 4.0.x-dev
Issue summary: View changes
Status: Active » Needs review

I got confused by this too, and Megan's comment in #5 is what finally cleared it up for me after first reviewing both the module's description and the README in the code. After following her instructions, I went into both the README and the help text on the settings form to make the steps clearer.

It also wasn't immediately clear to me that I had to enter the Google Analytics property ID before uploading the service account's credential JSON file; I worked through the form top-to-bottom and kept getting errors because I was uploading the JSON file without having put in the property ID. To alleviate the potential for that tripping people up in the future, I swapped the order of the two fields, so you're more likely to have entered the property ID before attempting to upload your credentials.

Both changes are available in the merge request that's now on this issue. Reviews and other thoughts welcome. Thanks!

ben.hamelin’s picture

Status: Needs review » Reviewed & tested by the community

Just came across this during setup and same problem. Reviewed the MR it looks good, updated status to get this updated documentation committed. Thanks all!

dstorozhuk’s picture

Documentation is not enough.
I was trying to set up the modules for the first time I spent just an incredible amount of time trying to understand which email I have to add to the Google Analytics itself.
Also, it is not clear from the documentation what is "numeric property ID for your Google Analytics property".

So we need to improve. But it is still much better that it was without a path.
It might be ok for site builders /developers, but definitely not ok for regular users.
If we wanted that module to be used in Drupal CSM - the documentation should be improved.

Also, was there an attempt to add Oauth and do the configuration of module on user behalf? Is that even possible? Does anyone do the research?

UPD: the email address you have to add is one which was created when the new key was generated. This will be some ugly string like @-.iam.gserviceaccount.com

rajab natshah’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +google_analytics_reports-4.0.1

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

rajab natshah’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.