I don't understand analytics, so I left GA4 and Search Console to Antigravity and got only the answers back
Don't you find it a bit of a hassle to open your browser and log in to the Google Analytics (GA4) or Search Console (GSC) dashboards every day just to check your site's traffic?
I've also always thought, 'It would be so much easier if I could just ask about this directly from the AI (Antigravity TED) editor screen I'm already working in...'
So, I decided to build an environment where I can pull data from GA4 and Search Console directly from the chat screen using 'MCP (Model Context Protocol),' a next-generation framework for connecting external tools to AI.
By being able to do this, after rewriting a blog post or site content, I can leave it to the AI agent I worked with to check how it performed and whether the SEO measures were successful. This not only significantly streamlines the workflow, but also allows me to run a cycle of 'rewrite → check status → further improvement' with the AI.
In this article, I will share the practical know-how I learned chronologically, including the 'authentication wall' I faced, the 'unexpected tricks,' and the gritty errors I encountered in the terminal. I hope this will be helpful for those who want to have AI analyze their marketing numbers.
Why connect 'access analysis' directly to AI now?
When running a site, checking the numbers is essential. However, because 'the GA4 menu structure has changed and it's hard to find the data I want' or 'it's a pain to keep switching back and forth with the GSC screen,' I sometimes stop opening the dashboards altogether.
What if you could just type 'How was the traffic today?' or 'Show me the traffic sources for the last week' into the AI chat box and get the data back instantly?
The 'MCP' standard makes this possible. It is a mechanism that gives AI (like Claude or editors like Cursor) the authority to say, 'You can use this function (in this case, Google's API) to look it up yourself.' You no longer need to go to a 'visual place' like a dashboard; you can naturally retrieve data within the 'flow of conversation' with the AI.
Preparation: Building the mechanism to pull GA4 data and the 'invisible wall'
First, to acquire GA4 data, I started by writing a dedicated MCP server (a backend program that handles data transfer) in Python.
Normally, for this kind of automation, you create a 'service account,' which is a backend key (JSON key) specifically for the system, to allow access. I also initially tried to create a service account on Google Cloud Platform (GCP) as usual.
However, I hit the first wall here.
To my surprise, due to the GCP organization policy restrictions I am using (security settings on the Google Workspace side), I was blocked by an error saying, 'Creation of service account keys is prohibited.' I couldn't change this policy with my own permissions, and I thought I was completely stuck. Honestly, seeing that screen and those words for the first time, I almost gave up!
So, I changed my strategy and decided to use 'OAuth authentication (user authentication for desktop apps),' which I had experience with before. This is a common login method where, every time the program (AI) is executed, a browser pops up for the first time and asks, 'Is it okay for this to read your Google account data?'
I ran the setup script for authentication in Python, pushed through the warning screen from the browser (the usual 'this page is not safe' one), and clicked the allow button, which finally allowed me to generate a spare key (access token) called `ga4_token.json` on my machine.
Integration: A trick to finish the tedious Search Console (GSC) setup in 'one second'
Once the GA4 integration was done, the next step was Google Search Console (GSC). It is an essential tool for having AI analyze what keywords are being searched for.
I thought, 'It's going to be a pain to go through the authentication process from scratch again,' but I was saved by an unexpected shortcut here.
Normally, when registering a new site in GSC, a very tedious procedure occurs where you have to 'add TXT information to the DNS record to prove that you are truly the owner of the domain.' It's that thing where you have to go into the server management screen and paste a string of characters you don't really understand.
However, actually, if you have already set up GA4 for the target site using the same Google account, you can skip this DNS verification entirely.
On the GSC property addition screen, select "URL prefix" on the right instead of "Domain property" on the left, enter the target URL (in my case, https://localseo-japan.com/ ), and click "Continue."
Then, a green pop-up saying "Ownership auto-verified (Verification method: Google Analytics)" popped up, and the integration was completed in literally one second.
This was the moment my hard work with GA4 paid off. All I had to do was reuse the "desktop app" authentication key (Client Secret) I created earlier for GSC as well to complete the authentication.
Practical Application: Overcoming Errors and the Moment the AI Read the Data
With all the parts in place, I finally ran the test to retrieve GA4 data from the AI.
However, the terminal spat out an error in bright red text.
UnicodeEncodeError: 'cp932' codec can't encode character '\U0001f464' in position 0: illegal multibyte sequenceThe cause was that I had included "emojis (👤, 📄, etc.)" in the Python script I wrote (or rather, that the AI agent TED wrote) to make the results easier to read. The standard character encoding (cp932) of the Windows command prompt and terminal could not interpret these emojis and froze.
I was trying to get the AI to perform advanced analysis, so it was a blind spot that I would stumble over such primitive "character encoding and emoji errors."
I immediately deleted the emojis from the script and ran it again with a prayer.
A few seconds later.
=== GA4 アクセス状況 (直近7日間) ===
アクティブユーザー数: 26
セッション数: 38
ページビュー数: 60
=== 主なトラフィック流入元 (直近7日間) ===
- (direct) / (none): 15 セッション
- google / organic: 10 セッション
- t.co / referral: 4 セッションBrilliantly, the AI accessed GA4 on its own and pulled up the real numbers for my site. The thrill of having the traffic from organic search and the referral path from X (t.co) delivered to me as actual numbers felt many times more rewarding than just opening a dashboard to look at them.
For readers who want to try it: The first step and points to note
If you also think, "I want to have an AI analyze my site" or "I want to try using MCP," please start with the following.
Start by testing with "safe data"
Instead of connecting directly to a production database containing customer information, it is recommended to start with "Read-Only data from GA4 or GSC" like I did this time."OAuth" is easy for authentication
Creating a service account in GCP is the standard way, but it can be blocked by security restrictions or have complex settings. If you are using a local environment by yourself, "desktop OAuth authentication," which you can quickly authorize in a browser, is overwhelmingly faster to set up.Be careful with how you handle credentials (authentication keys)!
Files like `client_secret.json` and `token.json` that you create and download along the way are essentially "duplicate keys" that can access your site data. Be sure to carefully configure your ".gitignore" so that you never upload them to public places like GitHub.
Now, my AI agent Antigravity (TED) has evolved beyond a "mere text assistant" into an "excellent data analyst" that understands the access status of my site.
I hope you will experience the feeling of removing the wall of the dashboard and engaging with marketing data through conversation.
💡 "I understand I can leave it to AI. So, what should I automate?" The answer to that is the complete automation of Google Maps review management and MEO measures. I have summarized the specific steps I actually used to build this with GoHighLevel (GHL) here.
👉 [Google Maps Management Agency via GoHighLevel (*Insert note link)]
Analytics and review management were both "tasks I didn't need to do myself."
From the day I realized that, everything changed.
