How to Send GA4 Events Without gtag/Tag Manager or Exposing Secret Key?

129 views
Skip to first unread message

Yureshwar Ravuri

unread,
Jul 20, 2025, 11:34:32 PM7/20/25
to Chromium Extensions
Hi everyone,

We are working on an Open Source Chrome extension: Digital Assistant Client

I'm trying to send event and page view data to Google Analytics 4 (GA4) without using the gtag.js script or Google Tag Manager.

Instead, I followed the official documentation to use the Measurement Protocol API:

 🔗 https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events

However, when making requests from the frontend, I'm running into CORS issues, and I also don’t want to expose my Measurement Protocol API secret key in the browser.
Is there a recommended or secure way to send GA4 data without using gtag.js, Tag Manager, or exposing the API secret on the frontend?

Any help or suggestions would be greatly appreciated!

Oliver Dunk

unread,
Jul 24, 2025, 6:31:25 AM7/24/25
to Yureshwar Ravuri, Chromium Extensions
Hi Yureshwar,

I'm not sure why you would be seeing CORS errors. If you send a correctly formatted POST request, the Measurement Protocol API will return the necessary CORS headers.

In general, exposing the Measurement Protocol API secret key is probably ok as it only allows for writing new data to your property. However, if you are concerned about this, the right approach would be to set up your own server endpoint that receives requests from the extension and then makes the relevant API call. I definitely appreciate being sensitive about exposing secrets in general and in most cases having these client side is usually a bad idea.

If you haven't seen it already, we have some guidance on using the Measurement Protocol API in extensions here: https://developer.chrome.com/docs/extensions/how-to/integrate/google-analytics-4
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/3da27712-8f4b-48f3-be3d-7dc9167bcbebn%40chromium.org.

Andrés Villanueva

unread,
Aug 26, 2025, 3:26:49 PM8/26/25
to Chromium Extensions, Yureshwar Ravuri
Hi Yureshwar, 

I'm trying to implement GA4, but Im having an issue. 
I'm not able to create the Secret Key (image 1)

I'm noticed that if I'm going to other project in GA, options to create the secret is available, image2 

Could you help me? I can pay you if you decide it. 

Xnapper-2025-08-26-16.22.30.png
Xnapper-2025-08-26-16.25.57.png

Oliver Dunk

unread,
Aug 27, 2025, 4:27:56 AM8/27/25
to Andrés Villanueva, Chromium Extensions, Yureshwar Ravuri
Hi Andrés,

You will need to create a new Google Analytics property for this.

The property created for your Chrome Web Store analytics is only for data from the Chrome Web Store, and you are only granted limited access to that.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
Reply all
Reply to author
Forward
0 new messages