mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 00:48:04 +08:00
- Added AmplitudeProvider component to initialize Amplitude analytics. - Updated layout components to include AmplitudeProvider for tracking. - Introduced utility functions for tracking events, setting user ID, and managing user properties. - Updated package.json and pnpm-lock.yaml to include @amplitude/analytics-browser dependency.
38 lines
869 B
TypeScript
38 lines
869 B
TypeScript
import * as amplitude from '@amplitude/analytics-browser'
|
|
|
|
/**
|
|
* Track custom event
|
|
* @param eventName Event name
|
|
* @param eventProperties Event properties (optional)
|
|
*/
|
|
export const trackEvent = (eventName: string, eventProperties?: Record<string, any>) => {
|
|
amplitude.track(eventName, eventProperties)
|
|
}
|
|
|
|
/**
|
|
* Set user ID
|
|
* @param userId User ID
|
|
*/
|
|
export const setUserId = (userId: string) => {
|
|
amplitude.setUserId(userId)
|
|
}
|
|
|
|
/**
|
|
* Set user properties
|
|
* @param properties User properties
|
|
*/
|
|
export const setUserProperties = (properties: Record<string, any>) => {
|
|
const identifyEvent = new amplitude.Identify()
|
|
Object.entries(properties).forEach(([key, value]) => {
|
|
identifyEvent.set(key, value)
|
|
})
|
|
amplitude.identify(identifyEvent)
|
|
}
|
|
|
|
/**
|
|
* Reset user (e.g., when user logs out)
|
|
*/
|
|
export const resetUser = () => {
|
|
amplitude.reset()
|
|
}
|