Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(name: string, attributes?: { [key: string]: string }) => {
if (analyticsEnabled) {
if (attributes == null) {
Analytics.record({ name: name })
} else {
Analytics.record({ name, attributes })
}
}
},
[analyticsEnabled]
Auth.configure(amplifyConfig)
const analyticsConfig = {
AWSPinpoint: {
appId: process.env.AMPLIFY_PINPOINT_APPID,
region: process.env.AMPLIFY_PINPOINT_REGION,
mandatorySignIn: false
}
}
Analytics.configure(analyticsConfig)
const initilalized = (window as any).initilalized
if (!initilalized) {
;(window as any).initilalized = true
Analytics.record('init')
}
export function useAnalytics() {
const { preferences } = usePreferences()
const analyticsEnabled = preferences['general.enableAnalytics']
const report = useCallback(
(name: string, attributes?: { [key: string]: string }) => {
if (analyticsEnabled) {
if (attributes == null) {
Analytics.record({ name: name })
} else {
Analytics.record({ name, attributes })
}
}
},
componentDidUpdate(prevProps, prevState) {
const attributes = Object.assign({}, this.props, this.state);
if (Analytics && typeof Analytics.record === 'function') {
Analytics.record({
name: this.trackerName,
attributes,
});
} else {
throw new Error(
'No Analytics module found, please ensure @aws-amplify/analytics is imported'
);
}
}