Skip to content

Commit

Permalink
wip: analytics tweaks based on feedback
Browse files Browse the repository at this point in the history
see: #980

License: MIT
Signed-off-by: Oli Evans <oli@tableflip.io>
  • Loading branch information
olizilla committed Mar 6, 2019
1 parent 45a2650 commit 3375804
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@tableflip/react-inspector": "^2.3.0",
"brace": "^0.11.1",
"chart.js": "^2.7.2",
"countly-sdk-web": "^18.11.0",
"countly-sdk-web": "^19.2.1",
"d3": "^5.7.0",
"details-polyfill": "^1.1.0",
"file-extension": "^4.0.5",
Expand Down
8 changes: 4 additions & 4 deletions public/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"downloadCopiedHash": "Download copied hash",
"downloadCopiedHashDescription": "Use <0>{ctrlKey}</0> + <2>{altKey}</2> + <3>D</3> to download the last copied hash.",
"AnalyticsToggle": {
"label": "Help improve this app by sending anonymous usage data",
"label": "BETA: Help improve this app by sending anonymous usage data",
"summary": "What data is collected?",
"paragraph1": "Protocol Labs hosts a <1>Countly</1> instance to record anonymous usage data for this app.",
"paragraph2": "The information collected includes:",
"item0": "A random, generated device ID",
"deviceId": "A random, generated device ID",
"item1": "Session duration",
"item2": "Country code & city from IP address. IP address is discarded",
"item3": "Operating system and version",
"item2": "Country code from IP address. IP address is discarded",
"item3": "Browser and OS version from User Agent string in `navigator.userAgent`",
"item4": "Display resolution and density",
"item5": "Locale (browser language, e.g German)",
"item6": "Browser information",
Expand Down
40 changes: 27 additions & 13 deletions src/bundles/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const createAnalyticsBundle = ({
countlyAppKey,
appVersion,
appGitRevision,
debug = false
debug = true
}) => {
return {
name: 'analytics',
Expand All @@ -24,24 +24,25 @@ const createAnalyticsBundle = ({
const Countly = root.Countly
Countly.q = Countly.q || []

Countly.require_consent = true
Countly.url = countlyUrl
Countly.app_key = countlyAppKey
Countly.app_version = appVersion
Countly.debug = debug

// Don't track clicks as it can include full url.
// Countly.q.push(['track_clicks']);
// Countly.q.push(['track_links'])
Countly.q.push(['group_features', {
activity: ['sessions', 'events', 'views']
}])

Countly.q.push(['track_sessions'])
Countly.q.push(['track_pageview'])
Countly.q.push(['track_errors'])

if (!store.selectAnalyticsEnabled()) {
Countly.q.push(['opt_out'])
Countly.ignore_visitor = true
}
// Don't track clicks or links as it can include full url.
// Countly.q.push(['track_clicks']);
// Countly.q.push(['track_links'])

Countly.init()
// Dont track errors as we can't gurantee they wont include CIDs or other personal info
// Countly.q.push(['track_errors'])

store.subscribeToSelectors(['selectRouteInfo'], ({ routeInfo }) => {
/*
Expand All @@ -53,6 +54,15 @@ const createAnalyticsBundle = ({
root.Countly.q.push(['track_pageview', routeInfo.pattern])
}
})

if (!store.selectAnalyticsEnabled()) {
console.log('ANAL OFF', root.Countly)
} else {
console.log('ANAL ON')
Countly.q.push(['add_consent', 'activity'])
}

Countly.init()
},

// Record durations for user actions
Expand Down Expand Up @@ -91,6 +101,7 @@ const createAnalyticsBundle = ({

reducer: (state = { lastEnabledAt: 0, lastDisabledAt: 0 }, action) => {
if (action.type === 'ANALYTICS_ENABLED') {
console.log('ANALYTICS_ENABLED')
return { ...state, lastEnabledAt: Date.now() }
}
if (action.type === 'ANALYTICS_DISABLED') {
Expand Down Expand Up @@ -122,14 +133,17 @@ const createAnalyticsBundle = ({
// user has not explicitly chosen
if (!lastEnabledAt && !lastDisabledAt) {
// ask to enable.
return true
// return true
// see: https://github.com/ipfs-shipyard/ipfs-webui/issues/980#issuecomment-467806732
return false
}
// user has already made an explicit choice; dont ask again.
return false
},

doToggleAnalytics: () => async ({ dispatch, store }) => {
const enable = !store.selectAnalyticsEnabled()
console.log('doToggleAnalytics', enable)
if (enable) {
store.doEnableAnalytics()
} else {
Expand All @@ -138,12 +152,12 @@ const createAnalyticsBundle = ({
},

doDisableAnalytics: () => async ({ dispatch, store }) => {
root.Countly.opt_out()
root.Countly.q.push(['remove_consent', 'activity'])
dispatch({ type: 'ANALYTICS_DISABLED' })
},

doEnableAnalytics: () => async ({ dispatch, store }) => {
root.Countly.opt_in()
root.Countly.q.push(['add_consent', 'activity'])
dispatch({ type: 'ANALYTICS_ENABLED' })
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/bundles/analytics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ it('should disable analytics if user has explicitly disabled it', () => {
expect(store.selectAnalyticsEnabled()).toBe(false)
})

it('should enable selectAnalyticsAskToEnable if user has not explicity enabled or disabled it', () => {
// see: https://github.com/ipfs-shipyard/ipfs-webui/issues/980#issuecomment-467806732
it.skip('should enable selectAnalyticsAskToEnable if user has not explicity enabled or disabled it', () => {
const store = createStore()
expect(store.selectAnalyticsAskToEnable()).toBe(true)
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/analytics-toggle/AnalyticsToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AnalyticsToggle = ({ doToggleAnalytics, analyticsEnabled, t }) => {
<Details summaryText={t('AnalyticsToggle.summary')} className='pt3'>
<p>
<Trans i18nKey='AnalyticsToggle.paragraph1'>
IPFS hosts a <a className='link blue' href='https://count.ly/'>Countly</a> instance to record anonymous usage data for this app.
Protocol Labs hosts a <a className='link blue' href='https://count.ly/'>Countly</a> instance to record anonymous usage data for this app.
</Trans>
</p>
<p>{t('AnalyticsToggle.paragraph2')}</p>
Expand Down

0 comments on commit 3375804

Please sign in to comment.