Google Analytics Admin API Basics

Google Analytics Admin API Basics

Guides an agent through enabling and using the Google Analytics Admin API: authentication, listing accounts and properties, and managing streams, dimensions and links, with code in seven languages.

Skill files8 files

references/

SKILL.md215 lines
1
---
2
name: google-analytics-admin-api-basics
3
metadata:
4
version: "1.0.0"
5
category: GoogleAnalytics
6
description: >-
7
Manages Google Analytics account and property settings, enables the Analytics Admin API via the Cloud CLI, lists accounts and properties, and manages data streams, custom dimensions, conversion events, and integrations. Use when you need to programmatically configure Google Analytics accounts, provision properties, manage data retention, configure Measurement Protocol secrets, or manage Firebase and Google Ads links.
8
---
9
10
# Getting Started with Google Analytics Admin API
11
12
The Google Analytics Admin API provides programmatic access to Google Analytics
13
account and property configuration. It lets you automate account management,
14
manage data streams, configure custom dimensions, and handle product
15
integrations.
16
17
## Enabling the API via Cloud CLI
18
19
Before making API calls, ensure the Google Analytics Admin API is enabled in
20
your Google Cloud project.
21
22
If `gcloud` is not found, prompt the user to install the Google Cloud CLI before
23
running these commands.
24
25
1. **Enable the API:** Use the Cloud CLI (`gcloud`) to enable
26
`analyticsadmin.googleapis.com`.
27
28
```bash
29
gcloud services enable analyticsadmin.googleapis.com --quiet
30
```
31
32
*Why: Enabling the API ensures your Cloud project has the necessary quota
33
and permissions allocated for managing Google Analytics configurations.*
34
35
2. **Verify API Enablement:**
36
37
```bash
38
gcloud services list --enabled --filter="analyticsadmin.googleapis.com"
39
```
40
41
## Authentication
42
43
To authenticate your API requests, you must generate Application Default
44
Credentials (ADC) and give your account the necessary scopes. Run the following
45
command in your terminal:
46
47
```bash
48
gcloud auth application-default login --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/analytics.readonly"
49
```
50
51
*Why: This configures ADC in your local environment with the required Cloud
52
Platform and Google Analytics read-only scopes, allowing the client library to
53
automatically authenticate your requests.*
54
55
> [!NOTE] **Configuration Changes**: Methods changing the Google Analytics
56
> account/property configuration will need the
57
> `https://www.googleapis.com/auth/analytics.edit` scope.
58
59
## Admin API Use Cases
60
61
You can use the Google Analytics Admin API to:
62
63
* Run Data Access reports (see
64
https://developers.google.com/analytics/devguides/config/admin/v1/access-api.md.txt
65
for more info)
66
* Create Account summaries
67
* Manage accounts
68
* Provision new accounts
69
* Search account change history events
70
* Manage and create properties
71
* Manage property data retention settings
72
* Manage conversion events
73
* Manage custom dimensions and metrics
74
* Manage data streams and configure measurement protocol secrets
75
* Manage Firebase links
76
* Manage Google Ads links
77
* Manage key events
78
79
### v1alpha-Only Use Cases
80
81
The following capabilities are currently available only in the `v1alpha` version
82
of the Admin API:
83
84
* Manage account and property access bindings
85
* Create and manage rollup properties
86
* Create and manage subproperties
87
* Acknowledge user data collection
88
* Change property attribution, data retention, Google signals, reporting
89
identity, and User Provided Data settings
90
* Manage AdSense links
91
* Manage BigQuery links
92
* Manage audiences
93
* Manage channel groups
94
* Manage calculated metrics
95
* Manage DisplayVideo360Advertiser links
96
* Manage expanded data sets
97
* Manage reporting data annotations
98
* Manage SearchAds360 links
99
* Manage event create rules for a data stream
100
* Manage SKAdNetwork conversion value schema of an iOS stream
101
* Submit a request for user deletion for a Google Analytics property.
102
103
## Calling the Admin API
104
105
To interact with the Admin API, use the official Google Analytics Admin client
106
library. Note that `v1beta` is the most stable version of the Admin API. For the
107
latest features, consider using `v1alpha`.
108
109
> [!IMPORTANT] **Mandatory Agent Directive:** When the user selects or requires
110
> a specific programming language, read the corresponding client library setup
111
> reference guide in `references/` listed below.
112
113
### Supported Client Libraries
114
115
#### Python
116
117
If you need to install or set up the Google Analytics Admin API client library
118
for Python, read the setup guide:
119
120
* [Python Installation Reference](references/python.md) *(Package:
121
`google-analytics-admin`)*
122
123
#### Java
124
125
If you need to install or set up the Google Analytics Admin API client library
126
for Java, read the setup guide:
127
128
* [Java Installation Reference](references/java.md) *(Artifact:
129
`com.google.cloud:google-cloud-analytics-admin`)*
130
131
#### PHP
132
133
If you need to install or set up the Google Analytics Admin API client library
134
for PHP, read the setup guide:
135
136
* [PHP Installation Reference](references/php.md) *(Package:
137
`google/analytics-admin`)*
138
139
#### Node.js
140
141
If you need to install or set up the Google Analytics Admin API client library
142
for Node.js, read the setup guide:
143
144
* [Node.js Installation Reference](references/nodejs.md) *(Package:
145
`@google-analytics/admin`)*
146
147
#### Go
148
149
If you need to install or set up the Google Analytics Admin API client library
150
for Go, read the setup guide:
151
152
* [Go Installation Reference](references/go.md) *(Package:
153
`cloud.google.com/go/analytics/admin/apiv1beta`)*
154
155
#### .NET
156
157
If you need to install or set up the Google Analytics Admin API client library
158
for .NET / C#, read the setup guide:
159
160
* [.NET Installation Reference](references/dotnet.md) *(Package:
161
`Google.Analytics.Admin.V1Beta`)*
162
163
#### Ruby
164
165
If you need to install or set up the Google Analytics Admin API client library
166
for Ruby, read the setup guide:
167
168
* [Ruby Installation Reference](references/ruby.md) *(Gem:
169
`google-analytics-admin-v1alpha`)*
170
171
> [!NOTE] **Additional Resources**: For further examples of calling the Admin
172
> API with Java, PHP, Node.js, .NET, Python, and REST, as well as hints on
173
> authentication with a service account, refer to the official
174
> [Admin API Quickstart](https://developers.google.com/analytics/devguides/config/admin/v1/quickstart).
175
> For complete API reference documentation for both `v1alpha` and `v1beta`, see
176
> the
177
> [Admin API Reference](https://developers.google.com/analytics/devguides/config/admin/v1/rest).
178
179
### Python Quick Start
180
181
1. **Install the Client Library:**
182
183
```bash
184
pip install google-analytics-admin
185
```
186
187
If `pip` is not available, prompt the user to install `pip` before
188
installing the client library.
189
190
2. **List Accounts and Properties:** Below is a complete example demonstrating
191
how to call the Admin API to list all available accounts and their child
192
properties for the current user using `list_account_summaries()`.
193
194
```python
195
from google.analytics.admin import AnalyticsAdminServiceClient
196
197
def sample_list_account_summaries():
198
# Initialize the client.
199
# Assumes Application Default Credentials (ADC) are configured in your environment.
200
client = AnalyticsAdminServiceClient()
201
202
# list_account_summaries returns a summary of all accounts accessible to the
203
# user and their child properties.
204
account_summaries = client.list_account_summaries()
205
206
print("Available Google Analytics Accounts and Properties:")
207
for summary in account_summaries:
208
print(f"Account: {summary.display_name} ({summary.account})")
209
for property_summary in summary.property_summaries:
210
print(f" Property: {property_summary.display_name} ({property_summary.property})")
211
212
if __name__ == "__main__":
213
sample_list_account_summaries()
214
```
215

© Google LLC · Apache 2.0 · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…