Skip to content

Commit

Permalink
feat: offlineAnalytics (#55)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Lichter <[email protected]>
  • Loading branch information
pooya parsa and TheAlexLichter committed Feb 7, 2019
1 parent 9ce84a1 commit 4c4d3ff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/modules/workbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ workbox: {

(Array) Additional scripts to be imported in service worker script. (Relative to `/`. Can be placed in `assets/` directory)

###offlineAnalytics*

(Boolean) Enable offline Google Analytics tracking [through workbox](https://developers.google.com/web/tools/workbox/guides/enable-offline-analytics) (Disabled by default)

### `offline`

(Boolean) Cache all routes. Enabled by default.
Expand Down
2 changes: 2 additions & 0 deletions packages/workbox/lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = {
offlinePage: null,
offlineAssets: [],

offlineAnalytics: false,

cachingExtensions: [],
routingExtensions: [],

Expand Down
5 changes: 5 additions & 0 deletions packages/workbox/templates/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ workbox.clientsClaim()
workbox.skipWaiting()
<% } %>

<% if (options.offlineAnalytics) { %>
// Enable offline Google Analytics tracking
workbox.googleAnalytics.initialize()
<% } %>

// --------------------------------------------------
// Precaches
// --------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions test/fixture/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
},

workbox: {
offlineAnalytics: true,
config: {
debug: true
},
Expand Down

0 comments on commit 4c4d3ff

Please sign in to comment.