Go to main content Go to main menu

Creating a Google Service Account

Before AI Assistant can access Google APIs, you need to create a service account in Google Cloud Console. A service account represents your application (not a user) and is used for secure, programmatic access to services such as: Google Search Console, Google Analytics. All access is performed using a service account under your control, ensuring that your data remains secure and is never shared with or transferred to third parties.

Steps to Create a Service Account

1. Create a Google Cloud Project (Skip if already exists)

If you already have a project in Google Cloud Console, you can skip this step. Otherwise:

  1. Go to Google Cloud Console
  2. Click Select Project → New Project
  3. Provide: Project Name
  4. Click Create

2. Enable Required APIs

Navigate to APIs & Services → Library, then enable:

For Google Search Console: Search Console API

For Google Analytics (GA4): Google Analytics Data API, Google Analytics Admin API.

For Google Ads: Google Ads API.

Google Ads requires the API to be enabled in the project used for authentication. See Google's project setup guide.

3. Create a Service Account

  1. Go to IAM & Admin → Service Accounts
  2. Click Create Service Account
  3. Fill: Name, ID (auto-generated)
  4. Click Create and Continue
  5. Roles: You can skip assigning roles here
  6. Click Done

4. Generate Service Account Key

  1. Open the created service account
  2. Go to Keys → Add Key → Create new key
  3. Choose: JSON 
  4. Download the file

⚠️ This JSON file contains credentials - you should store it securely. 

5. Grant Access in Google Search Console

  1. Go to Google Search Console
  2. Select your property (domain or URL prefix)
  3. Go to Settings → Users and permissions
  4. Click Add User
  5. Add the service account email (e.g. your-account-name@project.iam.gserviceaccount.com)
  6. Assign role: Full

6. Grant Access in Google Analytics (GA4)

  1. Go to Google Analytics
  2. Navigate:
    • Admin → Property Access Management
  3. Click + → Add users
  4. Add the service account email
  5. Assign role: Analyst

7. Grant Access in Google Ads

The service account must be added as a user in the specific Google Ads customer account (the advertiser account whose campaigns and metrics AI Assistant will read)

  1. Sign in to Google Ads as an administrator of that customer account. If you normally work from an MCC, switch into the customer account before adding the user.
  2. Open Admin → Access and security → Users and click +.
  3. Enter the service account's email, such as ai-assistant@your-project.iam.gserviceaccount.com.
  4. Choose Read-only access level and click Add account.
  5. Verify that the service account appears in the users list. Service accounts receive access directly, without accepting an email invitation.

These steps follow Google's service account workflow.

Configure the Service Account in Your Application

After creating the service account and granting the required permissions, configure its credentials in your application's settings.

For testing and development purposes only, you can configure the credentials locally. Production environments should use a secure secret management solution.

Development: Using .NET User Secrets (Recommended)

For ASP.NET Core applications, use .NET User Secrets to store service account credentials outside your source code and appsettings.json.

Step 1: Initialize User Secrets

Run the following command in your application project directory:

dotnet user-secrets init

Alternatively, specify the project explicitly:

dotnet user-secrets init --project ./YourApp/YourApp.csproj

Step 2: Add Service Account Credentials

If you have downloaded the Google service account JSON key file, use PowerShell to import its credentials:

$serviceAccount = Get-Content "./service-account.json" -Raw | ConvertFrom-Json

dotnet user-secrets set "Google:ServiceAccount:ProjectId" $serviceAccount.project_id
dotnet user-secrets set "Google:ServiceAccount:ClientEmail" $serviceAccount.client_email
dotnet user-secrets set "Google:ServiceAccount:PrivateKey" $serviceAccount.private_key

Run these commands from the application project directory. Replace the configuration keys if your application uses different settings.

The private key's original line breaks are preserved when reading the JSON file.

Important Notes

  • Private key formatting: Ensure the private key preserves its original line breaks (\n). When storing escaped newline sequences, convert them to actual line breaks if required.

  • Development: Prefer .NET User Secrets over storing credentials directly in appsettings.Development.json.

  • Production: Use secure credential management solutions, such as:

    • Azure Key Vault

    • Environment variables supplied by a secure deployment system

    • Cloud-native identity solutions where supported

  • Avoid hardcoding: Never embed service account credentials or private keys directly in source code.

  • Prevent accidental exposure: Do not commit service account JSON files or secrets to version control. Keep downloaded credential files outside the repository or exclude them using .gitignore.

  • User Secrets security: .NET User Secrets are stored outside the project directory but are not encrypted. Use them only for local development.

  • Least privilege: Grant the service account only the permissions required by your application.