Google Analytics 4 + Manifest v3

2,473 views
Skip to first unread message

Ryan Graham

unread,
Apr 20, 2022, 7:01:43 AM4/20/22
to Chromium Extensions
Yet another thread on the compatibility of Chrome Extensions with other Google Ecosystem Services, sorry...

We are trying to migrate our Chrome Extensions from Universal Analytics -> GA4 in preparation for the sunset of Universal Analytics next year. It doesn't appear to be ready. Here are our findings so far:

1) gtag.js cannot be used inside a service worker. It requires a window/document for all of the automatic telemetry capture & dynamic injection of scripts
2) Firebase Analytics is not supported inside a service worker
3) Measurement Protocol v2 functions but it is unable to capture any useful information. For example, it has no method for capturing Browser, OS, Language, Location, Demographic or Screen Views.
4) Content Scripts can't (shouldn't) be used for gtag.js. gtag dynamically injects <script> tags into the page, breaking out of the content script sandbox and potentially causing conflicts with existing gtag setups on the page.

In our current extensions, we are using a mix of https://github.com/googlearchive/chrome-platform-analytics and Measurement Protocol v1.

Launching a tab/window for gtag.js to access the window/document is clearly not an option here, as that presents the user with terrible UX.

Any suggestions/thoughts welcomed...

Thanks,

Cuyler Stuwe

unread,
Apr 20, 2022, 8:55:22 AM4/20/22
to Ryan Graham, Chromium Extensions
The impression I got was that Google didn’t really want us using wholesale general analytics products within Chrome extensions.

Instead, they wanted us to basically just craft our own event-based analytics.

--
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 on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/b39f92fa-9724-4545-b57d-79865a7c808an%40chromium.org.

Uladzimir Yankovich

unread,
Apr 20, 2022, 10:08:03 AM4/20/22
to Chromium Extensions, salem...@gmail.com, Chromium Extensions, Ryan Graham
I think you should try https://amplitude.com/ or https://mixpanel.com/. Unfortunately, the other options so far seem either completely broken or difficult to implement.

Ram Chaitanya

unread,
May 7, 2022, 1:31:51 AM5/7/22
to Chromium Extensions, yankovic...@gmail.com, salem...@gmail.com, Chromium Extensions, Ryan Graham
@yankovic- are there no restrictions on using a tool like mixpanel for user analytics?

Uladzimir Yankovich

unread,
May 7, 2022, 2:52:44 AM5/7/22
to Ram Chaitanya, Chromium Extensions, salem...@gmail.com, Ryan Graham
No, but i don't use sdk, only http api.

Hitesh Mittal

unread,
Jul 22, 2022, 7:35:02 AM7/22/22
to Chromium Extensions, yankovic...@gmail.com, Chromium Extensions, salem...@gmail.com, Ryan Graham, ramchai...@gmail.com
@yankovic Could you throw more light on how you implemented mixpanel or amplitude api for your analytics? Just starting out with a manifest v3 extension, and honestly a bit clueless at this point.

Uladzimir Yankovich

unread,
Jul 22, 2022, 7:58:22 AM7/22/22
to Chromium Extensions, hitesh...@pathora.in, Uladzimir Yankovich, Chromium Extensions, salem...@gmail.com, Ryan Graham, ramchai...@gmail.com
There's nothing complicated there. I advise you to use the HTTP API amplitude.

The basic solution design is this: your extension generates events, and puts them in local storage; every few minutes, the service worker sends them to your server, and your server processes the data and sends them to Amplitude's server.

This may seem a bit complicated. And definitely more complicated than website developers are used to, who simply insert the JS code of the SDK. But it's really not complicated and, most importantly, gives you much control.

Http API Amplitude docs — https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/.

It's much harder to decide what events you want to track, understand them, and make good product decisions based on them :)

Tomasz Ścisło

unread,
Sep 20, 2022, 5:22:55 PM9/20/22
to Chromium Extensions, yankovic...@gmail.com, hitesh...@pathora.in, Chromium Extensions, salem...@gmail.com, Ryan Graham, ramchai...@gmail.com
Anyone was able to use https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/web-js in service worker extension with v3?

Omar

unread,
Oct 11, 2022, 3:44:13 PM10/11/22
to Chromium Extensions, sci...@gmail.com, yankovic...@gmail.com, hitesh...@pathora.in, Chromium Extensions, salem...@gmail.com, Ryan Graham, ramchai...@gmail.com
My understanding is you are not able to use Google analytics approach because manifest v3 prohibits remotely loading code (see https://developer.chrome.com/docs/extensions/mv3/intro/mv3-overview/#remotely-hosted-code). Yankovic's approach to use the HTTP API on Mixpanel or Amplitude is a good solution. I'm going to try to implement it in my project.

Tomasz Ścisło

unread,
Oct 11, 2022, 5:46:20 PM10/11/22
to Omar, Chromium Extensions, yankovic...@gmail.com, hitesh...@pathora.in, salem...@gmail.com, Ryan Graham, ramchai...@gmail.com
I was able to do this (run old GA script) successfully by bundling ga script in my extension v3 and using it in content script, which has no limitations
--
Kind Regards / Pozdrawiam
Tomasz Ścisło
sci...@gmail.com

Omar

unread,
Oct 11, 2022, 6:27:41 PM10/11/22
to Chromium Extensions, sci...@gmail.com, Chromium Extensions, yankovic...@gmail.com, hitesh...@pathora.in, salem...@gmail.com, Ryan Graham, ramchai...@gmail.com, Omar

Nice! 🙂 I used the HTTP API on Mixpanel and successfully added analytics to my Chrome Extension 👍

Hidemitsu Hashimoto

unread,
Mar 29, 2023, 7:06:22 AM3/29/23
to Chromium Extensions, Omar, sci...@gmail.com, Chromium Extensions, yankovic...@gmail.com, hitesh...@pathora.in, salem...@gmail.com, Ryan Graham, ramchai...@gmail.com
Hi peoples.

I see today a Google announce about GA4 to Chrome Web Store Developer Dashboard.

Anyone know some new about GA4 + Chrome Extension Manifest V3 compatibility?

Reply all
Reply to author
Forward
0 new messages