A question on Google Analytics and HTMLService

65 views
Skip to first unread message

Faustino Rodriguez

unread,
Jun 3, 2021, 2:22:36 PM6/3/21
to Google Apps Script Community
I am using a code based on Martin Hawksey example from this page in the client side code of a Sheets add-on
It used to work as expected in real-time and as historic stats
However 
- from some time now, most of the calls are not registered in Analytics stats
- and almost none in real time

When looking at the browser network inspector
- I see the analytics tag script gets loaded but no calls to /collect endpoint are made
- Is there something "new" blocking those calls to google-analytics?

Is the approach from this example still working for others?

Thanks, Fausto

dimud...@gmail.com

unread,
Jun 3, 2021, 5:33:35 PM6/3/21
to Google Apps Script Community
Just a sign of the times.

The analytics landscape has gone through some drastic changes over the last year or two. Mainly in response to the current push towards stronger Data Privacy across the web.

Most browsers are dropping support for 3rd party cookies which used to be a pillar of data collection. Legislative efforts such as the EU's GDPR, California's CCPA, and others have also played a major role in reshaping how web services capture data. Not to mention the power of public sentiment, where the average person is wary of sharing personally identifiable information on these platforms.

As a result, Google rolled out a new version of Google Analytics in the fall of 2020 and have been rapidly rolling out new APIs that do a better job at capturing data anonymously and deprecating those that don't (lest they get slapped with fines). 

So the APIs that the example script relied on is probably on their way out. It may be time to refactor your code.

I'd recommend looking into the new Google Analytics 4 Data and Admin APIs. They are still in beta but they are probably your best bet moving forward. 
 

Martin Hawksey

unread,
Jun 4, 2021, 3:46:22 AM6/4/21
to Google Apps Script Community
Hi Fausto,

As noted Google Analytics has moved on in part to address new browser/cookie requirements. 

I know GA4 takes a new approach but haven't had a chance to look closely at the implications. For measurement in scripts there is a new alpha of the measurement protocol used to directly send data https://developers.google.com/analytics/devguides/collection/protocol/ga4

I know Bruce Mcpherson is currently looking at this as part of his library measurement series and look forward to see what he uncovers :)

Martin

Faustino Rodriguez

unread,
Jun 4, 2021, 7:32:45 AM6/4/21
to Google Apps Script Community
Thanks you all for the feedback
It's weird though that the same Analytics tracking code (gtag) works perfect in a "regular" webapp, it is only failing within the add-on iframes, does that make sense?

p.s. the GA4 approach is a bit intimidating on a first look

Bruce Mcpherson

unread,
Jun 7, 2021, 9:24:31 AM6/7/21
to google-apps-sc...@googlegroups.com
Hi Faustino
Yes - it is intimidating - I can't make any sense of it all yet for server side event tracking.



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/db4e6d0a-b37a-448b-bdd4-996a1318470dn%40googlegroups.com.

Faustino Rodriguez

unread,
May 23, 2023, 11:01:25 AM5/23/23
to Google Apps Script Community
Is anybody out there successfully using Google Analytics (GA4) client side (HtmlService for sidebar and dialog) ?
I am trying with the standard Google tag (see code below)
- But it is now working at all
- When looking at the Network traffic I see no calls (collect?v=) to the Analytics end-point

Thanks in advance for your help

<!-- Google tag (gtag.js) -->

<script async src="https://www.googletagmanager.com/gtag/js?id=G-1ABCDEF234"></script>

<script>

  window.dataLayer = window.dataLayer || [];

  function gtag(){dataLayer.push(arguments);}

  gtag('js', new Date());


  gtag('config', 'G-4RVELZF362');

</script>


Reply all
Reply to author
Forward
0 new messages