Skip to content

Commit

Permalink
fix: disable countly metrics (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki authored Apr 18, 2024
1 parent 0f7217d commit 68733bd
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 167 deletions.
11 changes: 0 additions & 11 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
},
"dependencies": {
"@dutu/rate-limiter": "github:dutu/rate-limiter#v1.3.1",
"countly-sdk-web": "^23.2.2",
"url-ponyfill": "^0.5.10"
},
"devDependencies": {
Expand Down
105 changes: 0 additions & 105 deletions src/countly.d.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { Workbox } from 'workbox-window'
import gateways from '../gateways.json'
import { Checker } from './Checker'
import { Log } from './Log'
import { loadCountly } from './metrics'
import { loadMetrics } from './metrics'

const wb = new Workbox('/sw.js')
void wb.register()

loadCountly()
// note: currently disabled and `.metricsConsentToggle` is currently display:none;
loadMetrics()
const log = new Log('App index')

window.checker = new Checker()
Expand Down
53 changes: 5 additions & 48 deletions src/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Countly from 'countly-sdk-web'

const metricsConsent = localStorage.getItem('metrics_consent')

const metricsNotificationModal = document.querySelector('.js-metrics-notification-modal')
Expand All @@ -16,7 +14,7 @@ const necessaryMetricsToggle = document.querySelector('.js-necessary-toggle') as
const metricsModalToggle = document.querySelector('.js-metrics-modal-toggle')

function addConsent (consent: string[]): void {
Countly.add_consent(consent)
// TODO: add consent to metrics provider

if (Array.isArray(consent)) {
localStorage.setItem('metrics_consent', JSON.stringify(consent))
Expand All @@ -40,7 +38,7 @@ function updateNecessaryMetricPreferences (): void {
if (necessaryMetricsAccepted) {
addConsent(['minimal'])
} else {
Countly.remove_consent(['minimal'])
// TODO: remove consent from metrics provider
localStorage.setItem('metrics_consent', JSON.stringify([]))
}
}
Expand Down Expand Up @@ -76,50 +74,9 @@ function metricsModalToggleEventHandler (): void {
initMetricsModal()
}

function loadCountly (): void {
function loadMetrics (): void {
metricsModalToggle?.addEventListener('click', metricsModalToggleEventHandler)
Countly.init({
app_key: '3c2c0819434074fc4d339ddd8e112a1e741ecb72',
url: 'https://countly.ipfs.io',
require_consent: true, // this true means consent is required
})
/**
* @see https://support.count.ly/hc/en-us/articles/360037441932-Web-analytics-JavaScript-#features-for-consent
*/

const minimalFeatures = ['sessions', 'views', 'events']
const performanceFeatures = ['crashes', 'apm']
const uxFeatures = ['scrolls', 'clicks', 'forms']
const feedbackFeatures = ['star-rating', 'feedback']
const locationFeatures = ['location']

Countly.group_features({
all: [
...minimalFeatures,
...performanceFeatures,
...uxFeatures,
...feedbackFeatures,
...locationFeatures,
],
minimal: minimalFeatures,
performance: performanceFeatures,
ux: uxFeatures,
feedback: feedbackFeatures,
location: locationFeatures,
})

/**
* we can call all the helper methods we want, they won't record until consent is provided for specific features
*/
//
Countly.track_clicks()
Countly.track_errors()
Countly.track_forms()
Countly.track_links()
Countly.track_pageview()
Countly.track_scrolls()
Countly.track_sessions()
Countly.track_view()
// TODO: initialize metrics provider

if (metricsConsent != null) {
addConsent(JSON.parse(metricsConsent))
Expand All @@ -128,4 +85,4 @@ function loadCountly (): void {
}
}

export { loadCountly, Countly }
export { loadMetrics }
2 changes: 2 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ button#metrics-notification-warning-close {
* From https://unpkg.com/@beyonk/[email protected]/dist/style.css
*/
.metricsConsentToggle {
/* TODO: make visible when we implement other metrics */
display: none;
width: 43px;
height: 43px;
will-change: transform;
Expand Down

0 comments on commit 68733bd

Please sign in to comment.