10.9 Set up API Project
This chapter will guide you through the process of creating a Google API project for Beehive.
Google API projects are created in the Google Cloud Console and involve configuring one or more Google APIs to service websites and other applications. For your analytics needs in Beehive, you’ll be combining several APIs from the Google API library into a single, robust data collection and reporting profile.
Begin by signing into a Google or Google Workspace account you wish to associate with the site on which Beehive is being configured, then navigate to the APIs & Services Dashboard in your Google Cloud Console. If this is your first time accessing the console, agree to the Terms and Service to proceed.
Click Create Project to initiate a new project.
If you don’t see the Create Project link, it may be that an API project was created with this account at some point in the past, possibly unrelated to Beehive.
In this case, click the Select a project drop-down and then click New Project. This is the screen you will come to if you ever wish to modify your Beehive API project or any other Google API projects you may initiate.
Enter any name you like for the Project name. If you are using a Google Workspace account, select the Organization and/or Location you want to associate with it, then click Create.
10.9.1 Enabling APIs
There are 5 APIs that you will need to enable, as follows:
- Google Analytics API – this API enables those with established credentials to configure the data collection and the reporting profile for a specific property.
- Google Analytics Reporting API – this API enables authorized users to build custom dashboards in Google Analytics, automate complex reporting tasks, and integrate with applications like Beehive.
- Google Analytics Data API – this API allows for programmatic access to the report data of the connected account so your Google Analytics 4 data can be displayed in your site admin.
- Google Analytics Admin API – this API allows for programmatic access to the configuration data of the connected account to fetch the list of GA4 properties associated with that account.
- Google People API – this API collects user profile and contact information for consenting users and shares that data with Google Analytics.
To get started, click the + Enable APIs and Services link to access the Google library of APIs.
For each of the 5 APIs listed above, use the search tool to locate it.
Click on the corresponding result. For example, you would see this when searching for the Google Analytics API:
On the next screen, click the Enable button to enable the API.
If you are prompted to create credentials, ignore the request, and exit the prompt. Google requires OAuth 2.0 credentials for API connections, but it is better to add all the required APIs before creating those credentials.
Once all 5 required APIs are added to the project, it’s time to create the OAuth Client ID.
10.9.2 Credentials and Consent Screen
Google requires informed user consent for most of its data collection APIs. In the case of Beehive, Google requires an OAuth 2.0 Client ID which, in turn, requires that users grant consent to the data collection via a consent screen. First, we will configure the consent screen, then the Client ID.
OAuth 2.0 and Google Verification
OAuth 2.0 is a protocol intended to ensure users whose data is being collected and handed off to a third-party have consented to that transaction. Google requires sites to identify the data collection app involved and to verify that data is being collected in accordance with Google policies before granting OAuth 2.0 credentials. Depending on the sensitivity of the data or the API involved, Google may require an application and its consent notification to submit to a verification process before providing those credentials. See the Scopes and Verification section of this guide for more information about that verification process.
There are many routes to the OAuth credential screen, but the following path is the most direct.
First, navigate to your Google API Project Dashboard by clicking Google APIs in the upper left corner. Once there, click the Oauth Consent Screen tab.
If you’re a Google Workspace user and want this app to be restricted to users within your organization, select the Internal option here. For all other cases, select External. Then click the Create button.
The following screen is where you’ll enter the info that appears on the consent screen when authorizing the app. As you will be the only one authorizing it for integration with Beehive, you should only need to fill in the following required fields:
- App name – enter any name you like
- User support email – use the same address as the Google account you’re logged-in with
- Developer contact email – same as above
Then click +Add Domain and enter your site’s domain name in the Authorized Domains section. Click Save & Continue.
You can ignore everything on the Scopes and Test Users screens, and simply click the Save & Continue button on each of those. Then, on the final Summary screen, click the Back to Dashboard button at the bottom.
On that next screen, click the Publish App button, then the Confirm button in the little modal that pops up.
Next, click on the Credentials tab and, in the +Create Credentials dropdown, select Oauth client ID.
Create Client ID
Complete the Create OAuth Client ID form as instructed below and click Create.
Application type – Select Web application and a series of settings relevant to web applications will appear.
Name – Here you are actually naming the credentials associated with this project. The name can be anything that works for you.
Authorized Javascript origins – All the javascript required for Beehive to function is contained in the app, so Admins can ignore this field.
Authorized redirect URIs– You must add the URI of the site being connected twice, once with a slash (/) at the end, and once without a slash (/) at the end.
You can quickly copy your URI redirects by navigating to the Accounts tab in Beehive. Under the Set up API Project section, you will notice a dropdown area for URI Redirects. Click on the row or the arrow to expand the section and you will be able to easily copy both of the URIs required for this step in the process.
When you are ready, click Create and Google will generate your credentials.
You can copy your Client ID and Client Secret key directly from this module or you can locate them at a later stage in your Credentials tab, as discussed below.
Locating Your Client Secret and Client ID
The Credentials screen contains a list of the Client IDs for all your Google API projects. Each Client ID will have an associated Client Secret, which can be viewed by clicking the name of the project or the pencil icon.
When you open the Client ID page, the Secret Key may not appear immediately. If not, simply refresh the page, and the key should appear beneath the Client ID.
The Client ID for this project cannot be changed, but users can reset the Client Secret as necessary by clicking Reset Secret.