From b103f44cb0dc06be00b3654a95cd847aa278cbbe Mon Sep 17 00:00:00 2001 From: razonyang Date: Tue, 28 Mar 2023 14:49:59 +0800 Subject: [PATCH] feat: add support for Google Analytics --- assets/mods/pwa/service-worker/index.ts | 5 +++++ exampleSite/layouts/_default/baseof.html | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/assets/mods/pwa/service-worker/index.ts b/assets/mods/pwa/service-worker/index.ts index 475cef6..7aeb4c8 100644 --- a/assets/mods/pwa/service-worker/index.ts +++ b/assets/mods/pwa/service-worker/index.ts @@ -3,6 +3,11 @@ import { CacheableResponsePlugin } from 'workbox-cacheable-response' import { ExpirationPlugin } from 'workbox-expiration' import { registerRoute, setCatchHandler } from 'workbox-routing' import { CacheFirst, NetworkFirst, NetworkOnly, StaleWhileRevalidate } from 'workbox-strategies' +import * as googleAnalytics from 'workbox-google-analytics' + +googleAnalytics.initialize({ + cacheName: 'hugo-pwa-google-analytics', +}) self.__WB_DISABLE_DEV_LOGS = !params.debug diff --git a/exampleSite/layouts/_default/baseof.html b/exampleSite/layouts/_default/baseof.html index 76a5a92..ba16368 100644 --- a/exampleSite/layouts/_default/baseof.html +++ b/exampleSite/layouts/_default/baseof.html @@ -1,9 +1,23 @@ - + {{ partialCached "pwa/assets/meta" . }} {{ partial "css" . }} + + + {{ partial "header" . }} @@ -12,7 +26,10 @@ {{ partialCached "tests" . }} {{ partial "js" . }} - + {{ partialCached "pwa/assets/sw" . }}