Google Analytics unable to connect to notebook

Hey Observable Community!

I’m trying to set up Google Analytics on a notebook and have tried all the implementations on these forums (I started here: Embedding Google Analytics - good or evil - poll - #4 by mbostock). I haven’t been able to get GA to receive any data from the notebook. I’m having trouble isolating where the problem is because as far as I can tell I’ve implemented the code correctly. Any ideas on how to debug the integration at all?

Thanks!

There could be a variety of causes. Can you share a link to your notebook?

For starters, you’ll want to open the network tab in your browser’s developer tools and check if Analytics sends any requests. Here you’ll also see if its attempts get blocked.

Next, be aware that the worker domain is different from the notebook domain. This may affect how GA processes the received data for the configured property.

1 Like

I am also struggling. Did you get it working? I have tried 4 different accounts, universal analytics and GA4, and I cannot get it to work I am not sure how it should be configured analytics side. Whether its observable domain or my subdomain (I tried both, but sometimes its laggy)

Not sure if this helps, but the origin for your code in observable can be found by typing this in your notebook:
location.origin
which in my case shows:
https://cobus.static.observableusercontent.com

Again, not sure if this is useful…

A fair number have wired GA up: (Observable. So not sure why mine is not working. I switched to UA + personal origin today I guess I will eventually get there. Would be helpful though if anyone has a working one to tell me how its configured w.r.t. to subdomains.

1 Like

Here is a link to the notebook (Page Analytics / Zachary Alan Kwiecinski / Observable), I have been able to see GA requests go through and to my knowledge they aren’t being blocked.

Thanks is the GA side setup as a property as owned by

  1. observablehq.com or
  2. ____.static.observableusercontent

In your notebook prose you state using a UA-XXX which is a universal analytics integration but your code is using a G-XXX code which is the later GA 4 integration. Which did you use and have working?

Probably none of these things are that important but I would like to know for the record.

I suspect its my consent mode that is messing things.

  1. I don’t believe it’s owned by either of those. It’s under our business account. But where would I confirm this?
  2. Sorry about that, the notebook was forked from a different forum post about GA but it was made at a time when the UA-XXX codes were in use. The G-XXX code is what is provided in the GA dashboard.

yeah I don’t think its critical the primary domain. For a GA4 is Admin → property → Data streams

Seems like its just something weird my end. Could be additional German requirements…

Yeah I still haven’t been able to get this working. To my knowledge the project I’m trying to set this up for only had it working for a couple hours almost a year ago so there was no guarantee that the code they used would still work. Especially after the big GA update that happened a few weeks ago.

1 Like

Yeah I haven’t been able to get this working yet either, ran out of time to investigate, but seems they might actually require you to put it in the head tag now?

2 Likes

I never got it working

I thought the issue had something to do with the worker process / url differences but I’m not positive. If it isn’t possible to do through regular notebook code anymore, I wonder if Observable might support some method outside of the notebooks to add it.

2 Likes

Plausible Analytics works ok and it’s about 5 min to setup :-

1 Like

well actually it still kinda sucks as the paths are all gibberish like:

https://endpointservices.static.observableusercontent.com/worker/worker.dd8ac99d17c9f197d09467ca7ab7f0e4da49ce322499f0115c95044bad2858dc.html

I wonder if there is a way to configure them to look sane

Cool! I seem to have at least partially fixed it by manually changing the upload payload. And I can publically share my stats and even embed the plausible dashboard in a notebook!

Out of all the analytics options, I think plausible is the least bad, it actively tries to avoid personal information so no GDPR consent is required (so they say, IANAL), and it provides all the hooks for total transparency. I shared all endpoint services stats!

1 Like

Some outstanding issues with Plausible Analytics

Whats good about the plausible analytics client is that it is quite hackable if you can somehow get the right information to it.

1 Like

Have started using Plausible off of your notebook, thanks for exploring this! I have also noticed the two issues you mentioned.

Regarding the second one, one partial solution might be to try to include the title of the notebook (fetched either through metadata if the script can access that, or from the text of the top cell). This would at least tell you which notebooks are embedded, if not where they are embedded. Might try this out and see if it works reliably.

Interesting I have an ink simulator that went viral enough to be linked in other sites. Mostly I lose this information but this site added ?ref=creativebrew and then it got picked up as a referrer in Plausible

Publication

Note the referer was not a domain name but just ‘creativebrew’ which was enough. This doesn’t really satisfactorily solve the referrer issue but it is interesting that sometimes information gets through.