Configure SearchConsole

To allow PagibleAI to interact with Google Search Console and PageSpeed Insights (CrUX), you need to set up API access via a Service Account and then grant that service account permissions within your Search Console property.

1. Get Chrome UX Report (CrUX) API Key

To retrieve CrUX metrics, you need to obtain an API key from Google Cloud Console and enable the Chrome UX Report API for your project.

  • Go to Google Cloud Console: Navigate to https://console.cloud.google.com/
  • Create or Select a Project: From the top bar, select an existing project or create a new one.
  • Enable Chrome UX Report API:
    • In the navigation menu, go to APIs & Services > Library.
    • Search for "Chrome UX Report API" and enable it for your project.
  • Create API Key:
    • In the navigation menu, go to APIs & Services > Credentials.
    • Click "+ CREATE CREDENTIALS" and select "API key".
    • A new API key will be generated. Copy this key.

2. Get Google Search Console API Key File

You will need to create a Service Account in Google Cloud and download its JSON key file.

  • Go to Google Cloud Console: Navigate to https://console.cloud.google.com/
  • Create or Select a Project: From the top bar, select an existing project or create a new one.
  • Enable Google Search Console API:
    • In the navigation menu, go to APIs & Services > Library.
    • Search for "Google Search Console API" and enable it for your project.
  • Create Service Account:
    • In the navigation menu, go to IAM & Admin > Service Accounts.
    • Click "+ CREATE SERVICE ACCOUNT".
    • Provide a Service account name (e.g., "PagibleAI-SearchConsole") and an optional description. Click "DONE".
  • Create and Download JSON Key:
    • Once the service account is created, click on its email address to view its details.
    • Go to the KEYS tab.
    • Click "ADD KEY" > "Create new key".
    • Select "JSON" as the key type and click "CREATE".
    • Your browser will download a JSON file (e.g., your-project-id-[hash].json). Save this file securely. This file contains your private key and is essential for API access.

3. Configure Google Search Console for API Access

After creating the service account and downloading its key file, you must grant the service account access to your website's data in Google Search Console.

  • Copy Service Account Email: From the Google Cloud Console (IAM & Admin > Service Accounts), copy the email address of the service account you just created.
  • Go to Google Search Console: Navigate to https://search.google.com/search-console/
  • Select Your Property: Choose the website property you want to connect to PagibleAI.
  • Add User:
    • In the left sidebar, click "Settings".
    • Click "Users and permissions".
    • Click "ADD NEW USER".
    • Paste the service account email address into the "Email address" field.
    • For Permission, select "Restricted" (for read-only access).
    • Click "ADD".

Your service account now has the necessary permissions to access your Search Console data via API. Store the downloaded JSON key file in a secure location on your PagibleAI server.

4. Add to PagibleAI CMS

Once you have your CrUX API key and the Google Auth key file, you need to add it to your PagibleAI environment configuration:

CRUX_API_KEY="..."
GOOGLE_AUTH="..."

The value of GOOGLE_AUTH must be the string from the Service Account JSON key file encoded as base64. To do the encoding on the command line, use:

php -r 'echo base64_encode(file_get_contents("name-xxxxxxxxxxxx.json"));'