workbox icon indicating copy to clipboard operation
workbox copied to clipboard

Better documentation for gtag in workbox-google-analytics

Open lc3t35 opened this issue 6 years ago • 3 comments

The current document for workbox-google-analytics (https://developers.google.com/web/tools/workbox/modules/workbox-google-analytics) has only example with former GA not gtag.

The migrate documentation (https://developers.google.com/analytics/devguides/collection/gtagjs/migration#send_custom_dimensions_and_metrics) and gtag documentation on dimensions and metrics (https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets) is not precise enough to clearly implement gtag with workbox-google-analytics.

When you create the dimension and metric, the code example states (in French) :

JavaScript (gtag.js)
Pour obtenir des instructions sur la configuration de dimensions personnalisées à l'aide de gtag.js, reportez-vous à la documentation pour les développeurs gtag.js. (https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets)

An additional example with gtag would really help.

If GA's created dimension is "dimension1" and "metric1" for metric, does workbox-google-analytics uses the same code for gtag with cd1 for dimension1 and cm1 for metric1 ?

googleAnalytics.initialize({
  parameterOverrides: {
    cd1: 'offline',
  },
  hitFilter: (params) => {
    const queueTimeInSeconds = Math.round(params.get('qt') / 1000);
    params.set('cm1', queueTimeInSeconds);
  },
});

lc3t35 avatar Mar 02 '20 15:03 lc3t35

CC: @philipwalton for feedback.

jeffposnick avatar Mar 02 '20 15:03 jeffposnick

I never got the "cd1" thing to work with GA4. I changed it to "up.network" and defined a user prop "network" in GA to track it. The documentation is annoyingly behind Google's change pace.

moos avatar Feb 06 '21 23:02 moos

FYI: we have some thoughts on how to deal with offline analytics moving forward in the Workbox project at https://github.com/GoogleChrome/workbox/issues/3055

jeffposnick avatar Apr 01 '22 13:04 jeffposnick