Google Analytics Utilities

repository·main·Indexed 42 days ago

https://github.com/google-marketing-solutions/google-analytics-utilities

An Apps Script-based tool that extends Google Sheets to enable bulk management and reporting of Google Analytics 4 (GA4) configurations. It supports listing, creating, updating, and deleting resources such as properties, data streams, custom dimensions, custom metrics, and various account links. The tool includes a Linker utility deployed via Google Cloud Functions to automate linking for Google Ads and DV360 using CSV files.

Tokens
9K
Snippets
5
Records
40
Agent score
55%

What's inside Google Analytics Utilities

  1. Overview of Google Analytics Utilities

    main

    Google Analytics Utilities is an Apps Script tool used in conjunction with a Google Spreadsheet to manage Google Analytics 4 (GA4) settings in bulk or individually. It allows users to list, create, update, delete, and archive various GA4 resources directly from a spreadsheet interface.

    Supported Resources and Capabilities:

    ResourceCapabilities
    Account SummariesList
    PropertiesList, Create, Delete, Update
    Data StreamsList, Create, Delete, Update
    Custom DimensionsList, Create, Archive, Update
    Custom MetricsList, Create, Archive, Update
    Calculated MetricsList, Create, Archive, Update
    Key EventsList, Create, Delete
    Firebase LinksList, Create, Delete
    Google Ads LinksList, Create, Delete, Update
    DV360 LinksList, Create, Delete, Update
    Audiences SettingsList, Create, Delete, Update
    SA360 LinksList, Create, Delete, Update
    BigQuery LinksList
    User Access BindingsList, Create, Delete, Update
    Settings ReportCreate
    Expanded Data SetsList, Create, Delete, Update
    Easy Property CreationCreate
    Channel GroupsList, Create, Delete, Update
    Measurement Protocol SecretsList, Create, Delete, Update
    AdSense LinksList, Create, Delete
    Event Create RulesList, Create, Delete, Update
    Audience ListsList, Create, Check, Export
    Subproperty Event FiltersList, Create, Delete, Update
    Rollup Property Source LinksList, Create, Delete
    User Access ReportCreate
    AnnotationsList, Create, Delete, Update
  2. Set up the Linker utility

    main
    The Linker utility automates linking Google Ads, DV360, and sending DV360 link proposals. It uses a Google Cloud Function that processes a CSV file uploaded to a Google Cloud Storage input bucket and writes results to an output bucket. If processing takes longer than one hour, the function automatically re-uploads remaining settings to the input bucket to trigger a subsequent execution.
  3. Understand color coding and action messages in Google Analytics Utilities

    main

    The Google Sheets utility uses color coding and an 'Action Taken' column to provide feedback on GA4 configuration tasks:

    Color Coding for Rows:

    • White: Missing necessary fields.
    • Red: Ready to archive/delete (all required fields filled).
    • Green: Ready to create (all required fields filled).
    • Blue: Ready to update (all required fields filled).

    Action Taken Column:

    • Records the result of an operation (e.g., successful creation or update).
    • Records errors.
    • Troubleshooting: If you see Error 404: HttpResponseException, you are likely missing a value in the resource name column (or the account ID column in the Property Details sheet).
  4. Configure Service Account and OAuth Credentials for Linker

    main

    To use the Linker utility, you must configure a service account and obtain OAuth tokens via the Google OAuth Playground.

    1. Service Account Setup

    Create a service account in IAM & Admin > Service Accounts and grant it these roles:

    • Storage Admin
    • Eventarc Event Receiver
    • Cloud Run Invoker

    Navigate to APIs & Services > OAuth consent screen:

    • Create an internal OAuth consent screen.
    • Add the scope: https://www.googleapis.com/auth/analytics.edit

    3. OAuth Client ID

    Navigate to APIs & Services > Credentials:

    • Create an OAuth Client ID of type Web Application.
    • Add https://developers.google.com as an authorized JavaScript origin.
    • Add https://developers.google.com/oauthplayground as an authorized redirect URI.
    • Note your Client ID and Client Secret.

    4. Obtain Tokens via OAuth Playground

    1. Go to https://developers.google.com/oauthplayground.
    2. Select Google Analytics Admin API v1Beta and the scope https://www.googleapis.com/auth/analytics.edit.
    3. Click the gear icon and configure:
      • OAuth flow: server-side
      • OAuth endpoints: Google
      • Authorization endpoint: https://accounts.google.com/o/oauth2/v2/auth
      • Token endpoint: https://oauth2.googleapis.com/token
      • Access token location: Authorization header w/ Bearer prefix
      • Access type: Offline
      • Check Use your own OAuth Credentials and enter your Client ID and Client Secret.
    4. Click Authorize APIs, complete the consent flow, and click Exchange authorization code for tokens.
    5. Save your Refresh Token and Access Token.
  5. Deploy the Linker Cloud Function

    main

    Deploy a 2nd gen Cloud Function to process the Linker CSV files.

    1. Storage Setup

    Create two Google Cloud Storage buckets: one for input files and one for output files.

    2. Function Configuration

    1. Create a new 2nd gen Cloud Function.
    2. Set a Cloud Storage trigger pointing to your input bucket.
    3. Assign the service account created in the credentials step.
    4. Under Runtime, build, connections and security settings, configure:
      • Memory: 1 GiB (recommended)
      • Timeout: 3600s (1 hour)
      • Runtime service account: Your service account
    5. Set the following Runtime Variables:
      • OUTPUT_BUCKET: Name of your output bucket
      • CLIENT_ID: Your OAuth Client ID
      • CLIENT_SECRET: Your OAuth Client Secret
      • ACCESS_TOKEN: Your OAuth Access Token
      • REFRESH_TOKEN: Your OAuth Refresh Token
      • TOKEN_URI: https://oauth2.googleapis.com/token
    6. Set the Runtime to 3.11.
    7. Set the Entry point to main.
    8. Copy the provided Linker cloud function code and requirements.txt into the editor and deploy.
  6. Manage GA4 Properties (List, Create, Delete, Update)

    main

    Manage GA4 properties using the Property Details sheet.

    List Properties

    1. List GA4 account summaries first.
    2. Select the desired properties.
    3. Navigate to the Property Details sheet.
    4. Click Google Analytics Utilities > Properties > List.

    Create Properties

    1. Navigate to the Property Details sheet.
    2. Enter a new row with:
      • Account ID
      • Property name
      • Industry category
      • Time zone
      • Currency code
      • Data Retention Duration (Note: TWENTY_SIX_MONTHS, THIRTY_EIGHT_MONTHS, or FIFTY_MONTHS are only for 360 properties)
      • Reset User Data on New Activity
    3. Check the Create box.
    4. Click Google Analytics Utilities > Properties > Modify.

    Delete Properties

    1. Navigate to the Property Details sheet.
    2. Select the properties to delete.
    3. Click Google Analytics Utilities > Properties > Modify.

    Update Properties

    1. Navigate to the Property Details sheet.
    2. Modify fields like Property Name, Industry category, Time zone, Currency code, Data Retention Duration, or Reset User Data on New Activity.
    3. Check the Update box.
    4. Click Google Analytics Utilities > Properties > Modify.
  7. Manage Audience Lists in Google Analytics Utilities

    main

    You can manage GA4 audience lists directly from the Google Spreadsheet interface using the Google Analytics Utilities menu.

    List Audience Lists

    1. List GA4 account summaries.
    2. Select the properties for which you want to list audience lists.
    3. Navigate to the Audience Lists sheet.
    4. Click Google Analytics Utilities > Advanced > Audience Lists > List Audience Lists.

    Create Audience Lists

    1. Navigate to the Audience Lists sheet.
    2. Populate the following columns for each rule:
      • Property ID
      • Audience Resource Name
      • Dimensions (a comma-separated list, e.g., deviceId, userId)
      • Check the Create box. Tip: Use List Existing Audiences first to auto-populate IDs and Resource Names.
    3. Click Google Analytics Utilities > Advanced > Audience Lists > Create Audience Lists.

    Check Audience List State

    1. Navigate to the Audience Lists sheet.
    2. Enter the Audience List Resource Name and check the Check State box for the desired lists.
    3. Click Google Analytics Utilities > Advanced > Audience Lists > Check Audience List States.

    Export Audience Lists

    Warning: Do not attempt to export more than 100,000 - 150,000 users total across all selected lists in one run to avoid script errors.

    1. Navigate to the Audience Lists sheet.
    2. List your audience lists first via List Audience Lists.
    3. For each audience, configure:
      • Audience List Resource Name
      • Output Location: Set to Spreadsheet or BigQuery.
      • If Spreadsheet: Check new spreadsheet for a new file, or leave unchecked and provide a URL for an existing spreadsheet.
      • If BigQuery: Enter the existing project and dataset names, and a new table name (the table must not already exist).
      • Check the Export box.
    4. Click Google Analytics Utilities > Advanced > Audience Lists > Export Audience Lists.
  8. Manage DV360 Links

    main

    Manage Display & Video 360 (DV360) links via the "DV360 Links" sheet.

    List Links:

    1. Select properties from GA4 account summaries.
    2. Navigate to the "DV360 Links" sheet.
    3. Click Google Analytics Utilities > Links > DV360 > List.

    Create Links:

    1. In the "DV360 Links" sheet, enter Property ID, Advertiser ID, and boolean values for Ads Personalization Enabled, Campaign Data Sharing Enabled, and Cost Data Sharing Enabled.
    2. Check the Create box.
    3. Click Google Analytics Utilities > Links > DV360 > Modify.

    Update Links:

    1. Enter the new value for Ads Personalization Enabled (true/false).
    2. Check the Update box.
    3. Click Google Analytics Utilities > Links > DV360 > Modify.

    Delete Links:

    1. Check the Delete box for the target links.
    2. Click Google Analytics Utilities > Links > DV360 > Modify.
  9. Manage GA4 Audiences

    main

    Control GA4 audiences using the "Audiences" sheet.

    List Audiences:

    1. Select properties from GA4 account summaries.
    2. Navigate to the "Audiences" sheet.
    3. Click Google Analytics Utilities > Audiences > List.

    Create Audiences:

    1. In the "Audiences" sheet, enter Property ID, Audience Name, Audience Description, Membership Duration, and Filter Clauses.
    2. Optionally provide Event Trigger Name, Event Trigger Log Condition, and Exclusion Duration Mode (only for exclusion filters).
    3. Check the Create box.
    4. Click Google Analytics Utilities > Audiences > Modify.

    Update Audiences:

    1. Edit Audience Name or Audience Description.
    2. Check the Update box.
    3. Click Google Analytics Utilities > Audience > Modify.

    Delete Audiences:

    1. Check the Delete box for the target audiences.
    2. Click Google Analytics Utilities > Audiences > Modify.
  10. Use Easy Property Creation to clone GA4 properties

    main

    The Easy Property Creation feature allows you to use an existing GA4 property as a template to create new properties with pre-configured settings.

    Workflow

    1. List Templates: List GA4 account summaries, select template properties, navigate to the Easy Property Creation sheet, and click Google Analytics Utilities > Advanced > Easy Property Creation > List Templates.
    2. Configure New Properties: In the Easy Property Creation sheet, enter the following for each new property:
      • Account ID for New Property
      • New Property Name
      • (Optional) Edit or add settings in the various columns.
    3. Execute: Check the Create box for the desired rows and click Google Analytics Utilities > Advanced > Easy Property Creation > Create Properties.

    Note: Due to API limitations, Google Signals will not be enabled in newly created properties, even if they were enabled in the template property.

  11. Manage GA4 AdSense Links

    main

    Connect GA4 properties to AdSense via the AdSense Links sheet.

    Operations

    • List: Select properties, navigate to the AdSense Links sheet, and click Google Analytics Utilities > Links > AdSense > List.
    • Create: Enter Property ID and Ad Client ID, check the Create box, and click Google Analytics Utilities > Links > AdSense > Modify.
    • Delete: Check the Delete box for the target links and click Google Analytics Utilities > Links > AdSense > Modify.