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:
- Go to Google Cloud Console
- Click Select Project → New Project
- Provide: Project Name
- 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
- Go to IAM & Admin → Service Accounts
- Click Create Service Account
- Fill: Name, ID (auto-generated)
- Click Create and Continue
- Roles: You can skip assigning roles here
- Click Done
4. Generate Service Account Key
- Open the created service account
- Go to Keys → Add Key → Create new key
- Choose: JSON
- Download the file
⚠️ This JSON file contains credentials - you should store it securely.
5. Grant Access in Google Search Console
- Go to Google Search Console
- Select your property (domain or URL prefix)
- Go to Settings → Users and permissions
- Click Add User
- Add the service account email (e.g. your-account-name@project.iam.gserviceaccount.com)
- Assign role: Full
6. Grant Access in Google Analytics (GA4)
- Go to Google Analytics
- Navigate:
- Admin → Property Access Management
- Click + → Add users
- Add the service account email
- 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)
- 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.
- Open Admin → Access and security → Users and click +.
- Enter the service account's email, such as ai-assistant@your-project.iam.gserviceaccount.com.
- Choose Read-only access level and click Add account.
- 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.