Skip to content

Commit

Permalink
Add anonymizeIp to saber-plugin-google-analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
DMarby committed Aug 15, 2019
1 parent 99fbb16 commit f5a5d6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/saber-plugin-google-analytics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ const ID = 'google-analytics'

exports.name = ID

exports.apply = (api, { trackId = false } = {}) => {
exports.apply = (api, { trackId = false, anonymizeIp = false } = {}) => {
api.hooks.chainWebpack.tap(ID, config => {
config.plugin('constants').tap(([options]) => [
Object.assign(options, {
__GA_TRACK_ID__: JSON.stringify(trackId)
__GA_TRACK_ID__: JSON.stringify(trackId),
__GA_ANONYMIZE_IP: JSON.stringify(anonymizeIp)
})
])
})
Expand Down
4 changes: 4 additions & 0 deletions packages/saber-plugin-google-analytics/saber-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export default function({ router }) {
ga('create', __GA_TRACK_ID__, 'auto')
ga('send', 'pageview')

if (__GA_ANONYMIZE_IP) {
ga('set', 'anonymizeIp', true)
}

router.afterEach(to => {
ga('set', 'page', to.fullPath)
ga('send', 'pageview')
Expand Down

0 comments on commit f5a5d6e

Please sign in to comment.