Skip to content

Commit

Permalink
feat(workbox): let users enable offline GA tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlexLichter committed Apr 4, 2018
1 parent bd308ec commit 7cbcde6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/modules/workbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ workbox: {

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

**offlineAnalytics** - (Default: false) Enable offline Google Analytics tracking [through workbox](https://developers.google.com/web/tools/workbox/guides/enable-offline-analytics)

For list of all available options see [here](https://developers.google.com/web/tools/workbox/modules/workbox-build)

### Adding custom runtimeCaching items (For CDN)
Expand Down
8 changes: 5 additions & 3 deletions packages/workbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ function getOptions (moduleOptions) {
handler: 'cacheFirst'
}
],
runtimeCaching: []
runtimeCaching: [],
offlineAnalytics: false
}

const options = defaultsDeep({}, this.options.workbox, moduleOptions, defaults)
Expand Down Expand Up @@ -101,8 +102,9 @@ function addTemplates (options) {
wbOptions: {
cacheId: options.cacheId,
clientsClaim: options.clientsClaim,
directoryIndex: options.directoryIndex
}
directoryIndex: options.directoryIndex,
},
offlineAnalytics: options.offlineAnalytics
}
})

Expand Down
4 changes: 4 additions & 0 deletions packages/workbox/templates/sw.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ workboxSW.precache([])
%>
workboxSW.router.registerRoute(new RegExp('<%= r.urlPattern %>'), workboxSW.strategies.<%= r.handler %>(<%= strategy %>), '<%= r.method %>')
<% }) %>

<% if(options.offlineAnalytics){
workboxSW.googleAnalytics.initialize()
} %>

0 comments on commit 7cbcde6

Please sign in to comment.