-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
622 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { EventParams } from '@segment/analytics-next/dist/pkg/core/arguments-resolver'; | ||
import { useHasUserGivenDiagnosticPermissions } from '@store/settings'; | ||
import { getAnalytics } from '@utils/init-segment'; | ||
import packageJson from '../../package.json'; | ||
import { NETWORK } from '@constants/index'; | ||
|
||
export function useAnalytics() { | ||
const diagnosticsEnabled = useHasUserGivenDiagnosticPermissions(); | ||
const analytics = getAnalytics(); | ||
const defaultProperties = { | ||
version: packageJson.version, | ||
network: NETWORK, | ||
}; | ||
|
||
const defaultOptions = { | ||
context: { ip: '0.0.0.0' }, | ||
}; | ||
|
||
return { | ||
track: async (...args: EventParams) => { | ||
if (!analytics || !diagnosticsEnabled) return; | ||
const [eventName, properties, options, ...rest] = args; | ||
|
||
const prop = { ...defaultProperties, ...properties }; | ||
const opts = { ...defaultOptions, ...options }; | ||
|
||
return analytics.track(eventName, prop, opts, ...rest).catch(console.error); | ||
}, | ||
}; | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Analytics, AnalyticsBrowser } from '@segment/analytics-next'; | ||
|
||
let analytics: Analytics | null = null; | ||
|
||
export function initSegment() { | ||
const writeKey = process.env.SEGMENT_WRITE_KEY; | ||
|
||
if (writeKey) { | ||
AnalyticsBrowser.standalone(writeKey) | ||
.then(res => (analytics = res)) | ||
.catch(console.error); | ||
} else { | ||
console.warn('segment init aborted: No WRITE_KEY setup.'); | ||
} | ||
} | ||
|
||
export function getAnalytics() { | ||
return analytics; | ||
} |
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
Oops, something went wrong.