-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Google Analytics and replace it with Plausible
- Loading branch information
Showing
13 changed files
with
93 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type {EventOptions, PlausibleOptions} from 'plausible-tracker'; | ||
import Plausible from 'plausible-tracker'; | ||
import {init as sentryInit} from '@sentry/react'; | ||
|
||
import {apiUrl, sentryJS as SentryConfig} from './config'; | ||
|
||
const shouldLog = | ||
(!__DEV__ || document.location.search.includes('enable_logging')) && | ||
navigator.userAgent !== 'ReactSnap'; | ||
|
||
// Use a no-op trackEvent() in dev or when running ReactSnap | ||
let trackEvent: ( | ||
eventName: string, | ||
options?: EventOptions, | ||
eventData?: PlausibleOptions, | ||
) => void = () => {}; | ||
|
||
// Error logging | ||
if (shouldLog) { | ||
sentryInit({ | ||
dsn: SentryConfig.dsn, | ||
debug: __DEV__, | ||
environment: __DEV__ ? 'development' : 'production', | ||
tracesSampleRate: 0.0, | ||
tunnel: `${apiUrl}/error/log`, | ||
}); | ||
|
||
// Analytics | ||
const { | ||
enableAutoPageviews, | ||
enableAutoOutboundTracking, | ||
trackEvent: realTrackEvent, | ||
} = Plausible({ | ||
apiHost: __DEV__ ? 'https://hits.d.sb' : apiUrl, | ||
domain: 'dnstools.ws', | ||
trackLocalhost: true, | ||
}); | ||
|
||
enableAutoPageviews(); | ||
enableAutoOutboundTracking(); | ||
trackEvent = realTrackEvent; | ||
} | ||
|
||
export {trackEvent}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 1 addition & 10 deletions
11
src/DnsTools.Web/ClientApp/src/components/NavigationSideEffects.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,14 @@ | ||
import {useEffect, useRef} from 'react'; | ||
import {useEffect} from 'react'; | ||
import {useLocation} from 'react-router-dom'; | ||
|
||
/** | ||
* Side effects (eg. logging) that occur when client-side page navigation occurs. | ||
*/ | ||
export default function NavigationSideEffects() { | ||
const {pathname, search} = useLocation(); | ||
const hasInitialized = useRef(false); | ||
useEffect(() => { | ||
// Scroll to the top on route change | ||
window.scrollTo(0, 0); | ||
|
||
// Tell Google Analytics that the page has changed, but not for initial | ||
// load (as it does that for us automatically). | ||
if (hasInitialized.current && pathname !== '/blank') { | ||
ga('set', 'page', pathname); | ||
ga('send', 'pageview'); | ||
} | ||
hasInitialized.current = true; | ||
}, [pathname, search]); | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2007,11 +2007,6 @@ | |
"@types/minimatch" "*" | ||
"@types/node" "*" | ||
|
||
"@types/google.analytics@^0.0.40": | ||
version "0.0.40" | ||
resolved "https://registry.yarnpkg.com/@types/google.analytics/-/google.analytics-0.0.40.tgz#35526e9d78333423c430ade1c821ce54d0f0f850" | ||
integrity sha512-R3HpnLkqmKxhUAf8kIVvDVGJqPtaaZlW4yowNwjOZUTmYUQEgHh8Nh5wkSXKMroNAuQM8gbXJHmNbbgA8tdb7Q== | ||
|
||
"@types/graceful-fs@^4.1.2": | ||
version "4.1.5" | ||
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15" | ||
|
@@ -9625,6 +9620,11 @@ [email protected]: | |
dependencies: | ||
find-up "^3.0.0" | ||
|
||
plausible-tracker@^0.3.8: | ||
version "0.3.8" | ||
resolved "https://registry.yarnpkg.com/plausible-tracker/-/plausible-tracker-0.3.8.tgz#9b8b322cc41e0e1d6473869ef234deea365a5a40" | ||
integrity sha512-lmOWYQ7s9KOUJ1R+YTOR3HrjdbxIS2Z4de0P/Jx2dQPteznJl2eX3tXxKClpvbfyGP59B5bbhW8ftN59HbbFSg== | ||
|
||
[email protected]: | ||
version "1.6.4" | ||
resolved "https://registry.yarnpkg.com/pnp-webpack-plugin/-/pnp-webpack-plugin-1.6.4.tgz#c9711ac4dc48a685dabafc86f8b6dd9f8df84149" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters