Skip to content

Google Integration

ruslandoga edited this page Sep 13, 2024 · 4 revisions

Integrating with Google either to get search keywords for hits from Google search or for imports from GA4 can be frustrating.

The following screenshot-annotated guide shows how to do it all in an easy way: just follow the Google-colored arrows!


Here's the outline of what we'll do:


Set up OAuth on Google Cloud

Select or create a Google Cloud project

Go to Google Cloud console, for example, by clicking Go to console on Google Cloud landing page. If Google asks you to register, just do it.

Once there, select a project that you want to use for Plausible OAuth app.

If you don't have a project already, or if you want to isolate Plausible from all your other Google Cloud things, you should create a new project.


Here's how to create a new Google Cloud project

In the Select a project pop-up, click New project

Pick a descriptive name. Organizations don't matter.

Once the project is created, select it and make sure all the other steps happen within that project. Google is tricky and sometimes switches you to a "default" project.

And just like that, you have a new Google Cloud project! Please do make sure it stays selected.


Register an OAuth application for a domain

Search for APIs & Services or something like that.

Then in the left sidebar pick OAuth consent screen to begin the OAuth application registration.

Choose External for the application type since the other one requires a Google Workspace and that costs money.

On the next screen pick the name for your application and add your contact information.

Scroll down -- skipping optional fields -- and type in your domain name and contact information (again).

Skip the scopes.

Pick yourself as the test user, Google might complain about it but it works.

Click the final Save and continue and you have the OAuth application registered.

Issue an OAuth client and key for that application

Pick Credentials in the sidebar.

Click + Create credentials dropdown and select OAuth client ID

Pick Web application for the application type, type the name for the client, and add the redirect URL.

That redirect URL should be /auth/google/callback on your Plausible instance's BASE_URL

Copy these to your .env and restart the plausible container

$ cd plausible-ce # or wherever you cloned plausible-ce repo to

$ echo "GOOGLE_CLIENT_ID=974728454958-e1vcqqqs6hmoc394663kjrkgfajrifdg.apps.googleusercontent.com" >> .env
$ echo "GOOGLE_CLIENT_SECRET=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" >> .env

$ docker compose up -d
$ docker compose exec plausible sh -c 'echo $GOOGLE_CLIENT_ID'
974728454958-e1vcqqqs6hmoc394663kjrkgfajrifdg.apps.googleusercontent.com

👍

Verify the chosen domain on Google Search console

Did you notice that during OAuth application registratation there was a note about Authorized URLs saying that they need to be verified? Nevermind, we are doing it now.

Start by navigating to Google Search Console page.

Once there, either ensure that you've already verified your domain by checking the properties in the Select property dropdown on the left or pick one of the two ways to verify it. I only have screenshots for the "Domain" type so that's what I'm picking.

Whichever you pick, just follow the instruction in the pop-up, they are good.

Success looks like this.

With that, you are ready to integrate Plausible with Google Search and import Universal Analytics data. You can do both, neither, and anything in between.

Integrate with Google Search

Enable APIs for Google Search integration

Go back to Google Cloud, ensure you have the correct project selected, and search for Google Search Console API

Enable it.

Link it with Plausible

Go to the site settings on your Plausible dashboard.

In the settings select Integrations and press Continue with Google

If you see a warning instead, that means you haven't set the GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET environment variables correctly.

Choose the account that you added as the test user.

Trust our own application.

Trust more.

Allow viewing Search Console data.

Pick the property from Search Console.

And now we should be able to drilldown into Google search terms like on plausible.io

Import historical data from GA4

Exporting historical data from Google requires enabling multiple APIs:

Gotta Catch ‘Em All!

Enable APIs for exports on Google Cloud

Go back to Google Cloud, ensure you have the correct project selected, and search for Google Analytics API

Enable it.

Next search for Google Analytics Reporting API

And enable it.

Now search for Google Analytics Admin API

And also enable it.

Finally search for Google Analytics Data API

And enable it!

Phew!

Import into Plausible

Go to the site settings on your Plausible dashboard.

In the Imports & Exports settings section press on the Google Analytics button.

If you see a warning instead, that means you haven't set the GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET environment variables correctly.

Choose the account that you added as the test user.

Trust our own application.

Trust more.

Pick the view to import.

And then follow the Plausible directions.

Confirm everything's in order and start the import.

You'll receive an email once the data is imported.