Back to Blog
MeasurementMay 3, 20269 min read

How to connect GA4 to Visoryn for AI search traffic reporting

A step-by-step guide to connecting your website, Google Analytics 4 property, and Visoryn so you can monitor AI search referral traffic from ChatGPT, Perplexity, Gemini, Claude, and other assistants.

connect GA4 to VisorynGA4 AI search trafficGoogle Analytics 4 setupChatGPT referral trafficAI search referral analyticsGA4 Data API

What the GA4 connection actually does

Connecting GA4 to Visoryn has two separate parts. First, your website needs the Google tag so visits are collected in a Google Analytics 4 web data stream. Second, Visoryn needs read access to the same GA4 property through the Google Analytics Data API. The website tag sends sessions into GA4; Visoryn reads those sessions and identifies traffic whose source or referrer looks like an AI assistant or AI search engine.

This is not a whole-internet AI search panel. GA4 can only show visits to your own website or app. That makes the report useful for measuring downstream clicks from ChatGPT, Perplexity, Gemini, Claude, Microsoft Copilot, Brave Search, Kagi, You.com, and similar sources after those users land on your site.

Step 1: create or confirm your GA4 web data stream

Open Google Analytics, choose the correct account and GA4 property, then go to Admin and open Data streams. Select the Web stream for your public website, or create one if the site is not connected yet. The stream details page contains the Measurement ID, which starts with G-. That ID is the one used in your website tag.

Be careful not to confuse the Measurement ID with the numeric Property ID. The G- ID connects the website tag to a web data stream. The numeric Property ID is used later by the GA4 Data API and by Visoryn's server-side connection.

  • Use the Measurement ID that starts with G- for the website Google tag.
  • Use the numeric GA4 Property ID for VISORYN_GA4_PROPERTY_ID.
  • Use one GA4 property for the website you want to measure in the Visoryn dashboard.

Step 2: install the Google tag on your website

Install the Google tag on every public page that should be measured. For a direct gtag.js setup, the snippet should load the Google tag script with your G- Measurement ID and call gtag('config', 'G-XXXXXXXXXX'). For Google Tag Manager, configure a GA4 tag that uses the same Measurement ID and fires on page load.

In a Next.js website, the safest implementation is usually to place the tag once in the shared root layout or a central analytics component so every route is covered. After publishing, visit your website in a normal browser session and check GA4 Realtime. If Realtime does not show your visit, Visoryn will not have website traffic to read either.

  • The Measurement ID in your website code must match the web data stream in GA4.
  • The tag should be present on every route that matters, not only the home page.
  • If you use cookie consent, make sure your consent mode still allows analytics collection where legally permitted.

Step 3: find the numeric GA4 Property ID

Visoryn's GA4 Data API connection needs the numeric Property ID, not the G- Measurement ID. In Google Analytics, open Admin, select the correct GA4 property, then open Property settings. Copy the Property ID shown there. It should look like a number, for example 535583363.

This value maps to the API path used by the Google Analytics Data API. If the numeric ID is wrong, Visoryn may authenticate correctly but still read the wrong property or receive a permission error.

Step 4: grant API access with the right Google account

The Google account used to create the OAuth refresh token must have access to the GA4 property. Viewer or Analyst access is usually enough for read-only reporting. If the account can open the GA4 reports in the browser but the API still fails, confirm that the token was created with the analytics.readonly scope and that the GA4 Data API is enabled in the Google Cloud project.

For a server-side Visoryn setup, the required environment values are the numeric property ID, OAuth client ID, OAuth client secret, and OAuth refresh token. These values should stay on the server. Do not expose the client secret or refresh token in public browser code.

  • VISORYN_GA4_PROPERTY_ID: the numeric GA4 property ID.
  • VISORYN_GA4_OAUTH_CLIENT_ID: the OAuth client ID from Google Cloud.
  • VISORYN_GA4_OAUTH_CLIENT_SECRET: the OAuth client secret from the same OAuth client.
  • VISORYN_GA4_OAUTH_REFRESH_TOKEN: a refresh token created with read-only Analytics access.

Step 5: open the Visoryn GA4 dashboard and check the connection

After the environment values are configured, restart the Next.js server so the new variables are loaded. Open the Visoryn app, go to Resources, and open AI Search Traffic for GA4. Use Check connection to confirm that Visoryn can call the GA4 Data API for the selected date range.

A successful connection does not always mean AI referral traffic already exists. The dashboard may show total sessions while AI Search Referrals remains zero. That usually means GA4 is receiving website traffic, but no sessions in the selected date range matched AI assistant sources yet.

How Visoryn identifies AI search referral traffic

Visoryn groups sessions by GA4 dimensions such as session source, session medium, page referrer, landing page, country, and date. When the source or referrer matches known AI assistant and AI search domains, the session is counted as an AI search referral. The dashboard then shows AI referrals, organic search referrals, total GA4 sessions, AI share, detected engines, countries, landing pages, and trend lines.

This approach is intentionally conservative. It measures clicked traffic that reaches your site, not answer visibility inside an AI assistant. For complete GEO reporting, combine GA4 referral traffic with prompt monitoring, citation tracking, and brand visibility reporting.

Troubleshooting common setup issues

If Visoryn says GA4 is connected but shows no website sessions, start with the website tag. Confirm that the G- Measurement ID is installed on the live website, then visit the site and check GA4 Realtime. If GA4 Realtime is empty, the issue is with collection rather than Visoryn.

If Visoryn returns a permission or authentication error, check the API side. Confirm the numeric Property ID, the OAuth client ID and secret, the refresh token, the Google account's GA4 property access, and whether the GA4 Data API is enabled. If you regenerated OAuth credentials, regenerate the refresh token with the same client ID and secret that Visoryn uses.

  • No Realtime data in GA4: the website tag is missing, wrong, blocked, or not deployed to every page.
  • GA4 has sessions but Visoryn shows zero AI referrals: AI assistant sources have not sent clicked traffic yet.
  • API permission error: the OAuth Google account may not have access to the GA4 property.
  • Invalid grant or unauthorized client: regenerate the refresh token with the current OAuth client.

FAQ

Common questions

Do I need to connect my website to GA4 before using Visoryn's AI traffic dashboard?

Yes. Visoryn reads website traffic from your GA4 property. If the website is not sending sessions into GA4 through the Google tag or Google Tag Manager, the dashboard will not have traffic data to analyze.

Should I use the G- Measurement ID or the numeric Property ID in Visoryn?

Use the G- Measurement ID on the website tag. Use the numeric GA4 Property ID in Visoryn's server-side environment variable VISORYN_GA4_PROPERTY_ID.

Why does AI Share show 0% even though GA4 is connected?

AI Share is calculated as AI search referral sessions divided by all GA4 sessions in the selected date range. If GA4 has traffic but no session source or referrer matches an AI assistant domain, AI Share will be 0%.

Can GA4 measure all AI search visibility across the web?

No. GA4 measures traffic that reaches your own website. To understand whether AI engines mention or cite your brand before a click happens, combine GA4 referral reporting with prompt tracking and citation monitoring.