mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 02:57:57 +00:00 
			
		
		
		
	 62de25960c
			
		
	
	62de25960c
	
	
	
		
			
			* feat: install logrocket * feat: allow log rocket * feat: enable vuex log-rocket * feat: integrate vuex with log rocket * feat: add log rocket identify * fix: identify if log rocket is initialized --------- Co-authored-by: Vishnu Narayanan <vishnu@chatwoot.com>
		
			
				
	
	
		
			66 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import AnalyticsHelper from './AnalyticsHelper';
 | |
| import LogRocket from 'logrocket';
 | |
| import DashboardAudioNotificationHelper from './AudioAlerts/DashboardAudioNotificationHelper';
 | |
| 
 | |
| export const CHATWOOT_SET_USER = 'CHATWOOT_SET_USER';
 | |
| export const CHATWOOT_RESET = 'CHATWOOT_RESET';
 | |
| 
 | |
| export const ANALYTICS_IDENTITY = 'ANALYTICS_IDENTITY';
 | |
| export const ANALYTICS_RESET = 'ANALYTICS_RESET';
 | |
| 
 | |
| export const initializeAnalyticsEvents = () => {
 | |
|   window.bus.$on(ANALYTICS_IDENTITY, ({ user }) => {
 | |
|     AnalyticsHelper.identify(user);
 | |
|     if (window.logRocketProjectId) {
 | |
|       LogRocket.identify(user.id, {
 | |
|         email: user.email,
 | |
|         name: user.name,
 | |
|       });
 | |
|     }
 | |
|   });
 | |
|   window.bus.$on(ANALYTICS_RESET, () => {});
 | |
| };
 | |
| 
 | |
| const initializeAudioAlerts = user => {
 | |
|   // InitializeAudioNotifications
 | |
|   const { ui_settings: uiSettings } = user || {};
 | |
|   const {
 | |
|     always_play_audio_alert: alwaysPlayAudioAlert,
 | |
|     enable_audio_alerts: audioAlertType,
 | |
|     alert_if_unread_assigned_conversation_exist: alertIfUnreadConversationExist,
 | |
|     notification_tone: audioAlertTone,
 | |
|   } = uiSettings;
 | |
| 
 | |
|   DashboardAudioNotificationHelper.setInstanceValues({
 | |
|     currentUserId: user.id,
 | |
|     audioAlertType: audioAlertType || 'none',
 | |
|     audioAlertTone: audioAlertTone || 'ding',
 | |
|     alwaysPlayAudioAlert: alwaysPlayAudioAlert || false,
 | |
|     alertIfUnreadConversationExist: alertIfUnreadConversationExist || false,
 | |
|   });
 | |
| };
 | |
| 
 | |
| export const initializeChatwootEvents = () => {
 | |
|   window.bus.$on(CHATWOOT_RESET, () => {
 | |
|     if (window.$chatwoot) {
 | |
|       window.$chatwoot.reset();
 | |
|     }
 | |
|   });
 | |
|   window.bus.$on(CHATWOOT_SET_USER, ({ user }) => {
 | |
|     if (window.$chatwoot) {
 | |
|       window.$chatwoot.setUser(user.email, {
 | |
|         avatar_url: user.avatar_url,
 | |
|         email: user.email,
 | |
|         identifier_hash: user.hmac_identifier,
 | |
|         name: user.name,
 | |
|       });
 | |
|       window.$chatwoot.setCustomAttributes({
 | |
|         signedUpAt: user.created_at,
 | |
|         cloudCustomer: 'true',
 | |
|       });
 | |
|     }
 | |
| 
 | |
|     initializeAudioAlerts(user);
 | |
|   });
 | |
| };
 |