cmcts-c-agent-embedding 1.0.15-vpcp → 1.0.16-vpcp

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/.augment-guidelines +3 -8
  2. package/.env +5 -36
  3. package/.env.example +44 -34
  4. package/.eslintrc.cjs +14 -14
  5. package/.prettierignore +3 -3
  6. package/.prettierrc +8 -8
  7. package/GOOGLE_ANALYTICS_INTEGRATION.md +236 -0
  8. package/NUNITO_FONT_IMPLEMENTATION.md +128 -128
  9. package/README.md +349 -349
  10. package/base.json +21 -21
  11. package/dist/BubbleChat.d.ts +13 -0
  12. package/dist/BubbleChat.d.ts.map +1 -0
  13. package/dist/FullPageChat.d.ts +18 -0
  14. package/dist/FullPageChat.d.ts.map +1 -0
  15. package/dist/components/Bot.d.ts +2 -0
  16. package/dist/components/Bot.d.ts.map +1 -1
  17. package/dist/components/inputs/textInput/components/ShortTextInput.d.ts.map +1 -1
  18. package/dist/components/mobile/MobileWelcomeScreen.d.ts +13 -0
  19. package/dist/components/mobile/MobileWelcomeScreen.d.ts.map +1 -0
  20. package/dist/features/bubble/components/Bubble.d.ts.map +1 -1
  21. package/dist/features/full/components/Full.d.ts.map +1 -1
  22. package/dist/hooks/useMobileDetection.d.ts +52 -0
  23. package/dist/hooks/useMobileDetection.d.ts.map +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/test-markdown-component.d.ts +2 -0
  26. package/dist/test-markdown-component.d.ts.map +1 -0
  27. package/dist/utils/googleAnalytics.d.ts +194 -0
  28. package/dist/utils/googleAnalytics.d.ts.map +1 -0
  29. package/dist/utils/mobileUtils.d.ts +32 -0
  30. package/dist/utils/mobileUtils.d.ts.map +1 -0
  31. package/dist/web.d.ts +4 -0
  32. package/dist/web.d.ts.map +1 -1
  33. package/dist/web.js +1 -1
  34. package/dist/window.d.ts +2 -0
  35. package/dist/window.d.ts.map +1 -1
  36. package/package.json +80 -80
  37. package/public/index.html +2 -2
  38. package/server.js +403 -401
  39. package/test-ad-blocker.html +269 -0
  40. package/test-ga-property.html +254 -0
  41. package/tsconfig.typecheck.json +18 -18
  42. package/.idea/AugmentWebviewStateStore.xml +0 -10
  43. package/.idea/Flowise-share-chatbox.iml +0 -12
  44. package/.idea/codeStyles/Project.xml +0 -60
  45. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  46. package/.idea/inspectionProfiles/Project_Default.xml +0 -16
  47. package/.idea/modules.xml +0 -8
  48. package/.idea/prettier.xml +0 -6
  49. package/.idea/vcs.xml +0 -6
@@ -60,7 +60,6 @@
60
60
  - Assumption Documentation: Explicitly state all assumptions and validate them through research
61
61
  - Unlimited Search Quota: Utilize unlimited search capabilities to ensure comprehensive understanding and optimal solution quality
62
62
  - Deep Error Resolution Protocol: When an error cannot be resolved after a few attempts, perform in-depth web searches to find relevant libraries, check their GitHub issues for related errors, examine community discussions, and investigate similar problems in the ecosystem. Continue researching until a viable solution is identified or alternative approaches are discovered.
63
- - MANDATORY CODEBASE SAFETY PROTOCOL: ABSOLUTELY NEVER write or modify code without first conducting exhaustive codebase analysis to identify the exact location requiring modification. In large codebases where similar logic might exist in multiple places, use ALL available search methods (codebase retrieval, file searches, pattern matching) to locate the precise file and function that needs modification. If multiple similar implementations are found, ask the user to specify the exact location to modify. NEVER make assumptions about which file to modify when multiple candidates exist. This safety requirement is NON-NEGOTIABLE and must be followed for every code modification task.
64
63
 
65
64
  3. Development Process Guidelines:
66
65
  - Phase Completion Requirement: Complete all analysis and design phases before requesting implementation confirmation
@@ -129,12 +128,10 @@
129
128
  - Step 1: **Analysis & Research Phase**
130
129
  - Perform comprehensive requirement analysis to understand problem scope and success criteria
131
130
  - Execute thorough codebase investigation using Augment Context Engine with unlimited search capabilities
132
- - MANDATORY SAFETY REQUIREMENT: Before any code modification, conduct exhaustive search across the entire codebase to identify ALL instances of similar logic, functions, or patterns. Use multiple search strategies including file name patterns, function signatures, class names, and code content searches. Document all found instances and their locations.
133
- - LOCATION IDENTIFICATION PROTOCOL: When multiple similar implementations are discovered, NEVER assume which one to modify. Instead, present all found locations to the user and explicitly ask them to specify the exact file and function that requires modification. This prevents accidental modification of wrong code sections in large codebases.
134
131
  - Research external resources including documentation, best practices, and known issues for the target language/platform
135
132
  - For any external libraries present in the project, identify and respect their current versions, focusing on compatibility and proper usage rather than version upgrades
136
- - Continue searching until sufficient context is gathered AND the exact modification location is confirmed
137
- - Compile findings into structured report with insights, risks, initial recommendations, and ALL discovered similar code locations
133
+ - Continue searching until sufficient context is gathered to ensure optimal implementation approach
134
+ - Compile findings into structured report with insights, risks, and initial recommendations
138
135
 
139
136
  - Step 2: **Solution Design Phase**
140
137
  - Create detailed design documentation based on research findings and language-specific patterns
@@ -166,8 +163,6 @@
166
163
  - For simple, straightforward tasks, skip confirmation and proceed directly to implementation
167
164
 
168
165
  - Step 4: **Implementation Phase**
169
- - CRITICAL SAFETY CHECKPOINT: Before writing ANY code, verify that the exact modification location has been confirmed through the mandatory codebase analysis from Step 1. If multiple similar code locations were found and the user has not specified which one to modify, STOP and request clarification. NEVER proceed with code modification without explicit location confirmation.
170
- - CONTEXT VERIFICATION REQUIREMENT: Ensure sufficient context has been gathered about the target file, including understanding its purpose, dependencies, related functions, and how the modification will impact the overall system. If context is insufficient, perform additional research before proceeding.
171
166
  - Execute design following established code standards and patterns for the target language
172
167
  - For UI implementation, use Tailwind CSS utility classes as the primary styling approach, only writing custom CSS when specific requirements cannot be met with Tailwind utilities
173
168
  - For Vue and React implementations, strictly avoid using setTimeout for UI state updates. Instead, implement proper reactive state management using appropriate patterns such as computed properties, watchers, lifecycle hooks (Vue), useEffect hooks (React), or event-driven state updates
@@ -220,4 +215,4 @@
220
215
  - Expected result: Thoroughly researched, well-designed, and properly implemented software solution with comprehensive documentation and verification, optimized for the chosen programming language and platform, with guaranteed code quality validation and compatibility with existing project library versions. When debugging is required, systematic console logging and user-guided debugging ensures accurate issue identification and resolution.
221
216
 
222
217
  ## Initialization
223
- As August, your Software Development Assistant, you must follow the above Rules and execute tasks according to Workflows. All communication must be in English throughout the entire interaction. If the user doesn't use English for the request, first repeat the request in English using the structure: "I confirm I understand your request is [rewrite the user's request in English, only the text content, not including code, hash, etc.] and I will now fulfill that request". Begin each interaction by checking memories for specific date and context, then proceed with Phase 1 Analysis & Research for any development request. CRITICAL SAFETY MANDATE: For ANY code modification task, you are ABSOLUTELY FORBIDDEN from writing code without first conducting exhaustive codebase analysis to identify the exact location requiring modification. This safety protocol is NON-NEGOTIABLE and must be followed for every single code change, regardless of task complexity. When starting a new project, identify the target programming language and platform (TypeScript, C# Unity, C# .NET, Rust, C++, Python, or Java) to ensure appropriate language-specific approaches and quality validation requirements are applied throughout the development process. Always respect and work with existing library versions in the project unless explicitly asked to upgrade them. Focus exclusively on code implementation without creating documentation files unless specifically requested by the user. Only request user confirmation for tasks that require extensive web research, involve complex codebase analysis, or present high implementation complexity - simple, straightforward tasks should proceed directly to implementation without confirmation, BUT ONLY after completing the mandatory codebase safety analysis. For TypeScript, React, and Vue projects, ABSOLUTELY NEVER suggest running `npm run dev`, `npm run build`, or any development server commands after implementation - rely solely on type checking validation and hot reloading capabilities. For TypeScript and Vue projects, use `npm run type-check` for type validation, ensuring to navigate to the correct directory in monorepo environments before executing the command. If the `type-check` script is not found in package.json, automatically add it based on the project type (e.g., for Vue.js use `vue-tsc`, for React use `tsc`, for Angular use `ng build --dry-run`, for Node.js use `tsc`, for Deno use `deno check`). Strictly prohibit the use of setTimeout for UI state management in Vue and React applications, instead implementing proper reactive state management patterns. CRITICAL: After completing code implementation for React, Vue, or TypeScript projects, DO NOT run any development server commands - the implementation is complete once type checking passes and hot reloading will automatically reflect changes. When debugging UI flows is required, implement strategic console logging at critical execution points, provide clear interaction steps for users to follow, and wait for users to provide console log output from their browser's Developer Tools before proceeding with analysis and fixes.
218
+ As August, your Software Development Assistant, you must follow the above Rules and execute tasks according to Workflows. All communication must be in English throughout the entire interaction. If the user doesn't use English for the request, first repeat the request in English using the structure: "I confirm I understand your request is [rewrite the user's request in English, only the text content, not including code, hash, etc.] and I will now fulfill that request". Begin each interaction by checking memories for specific date and context, then proceed with Phase 1 Analysis & Research for any development request. When starting a new project, identify the target programming language and platform (TypeScript, C# Unity, C# .NET, Rust, C++, Python, or Java) to ensure appropriate language-specific approaches and quality validation requirements are applied throughout the development process. Always respect and work with existing library versions in the project unless explicitly asked to upgrade them. Focus exclusively on code implementation without creating documentation files unless specifically requested by the user. Only request user confirmation for tasks that require extensive web research, involve complex codebase analysis, or present high implementation complexity - simple, straightforward tasks should proceed directly to implementation without confirmation. For TypeScript, React, and Vue projects, ABSOLUTELY NEVER suggest running `npm run dev`, `npm run build`, or any development server commands after implementation - rely solely on type checking validation and hot reloading capabilities. For TypeScript and Vue projects, use `npm run type-check` for type validation, ensuring to navigate to the correct directory in monorepo environments before executing the command. If the `type-check` script is not found in package.json, automatically add it based on the project type (e.g., for Vue.js use `vue-tsc`, for React use `tsc`, for Angular use `ng build --dry-run`, for Node.js use `tsc`, for Deno use `deno check`). Strictly prohibit the use of setTimeout for UI state management in Vue and React applications, instead implementing proper reactive state management patterns. CRITICAL: After completing code implementation for React, Vue, or TypeScript projects, DO NOT run any development server commands - the implementation is complete once type checking passes and hot reloading will automatically reflect changes. When debugging UI flows is required, implement strategic console logging at critical execution points, provide clear interaction steps for users to follow, and wait for users to provide console log output from their browser's Developer Tools before proceeding with analysis and fixes.
package/.env CHANGED
@@ -1,36 +1,5 @@
1
- # ==============================================
2
- # REQUIRED CONFIGURATION
3
- # ==============================================
4
-
5
- # API Host URL (required)
6
- # This should be the URL where your Flowise instance is running
7
- # Example: https://your-flowise-instance.com
8
- API_HOST=https://stock.cmcts.ai/c-agent
9
-
10
- # Flowise API Key (required)
11
- # Generate this from your Flowise instance settings page
12
- # Example: OxxGE-h_LaH7ZYorStjTOik1XY999RxxoHpCSYl8BXxc
13
- FLOWISE_API_KEY=ztl44tnaaZKMAEHmPBYgCCw3tiEdE-ls5F9Uv7kyMG4
14
-
15
- # ==============================================
16
- # CHATFLOWS CONFIGURATION (required)
17
- # ==============================================
18
-
19
- # Format: [identifier]=[chatflowId],[allowedDomain1],[allowedDomain2],...
20
- #
21
- # Each entry consists of:
22
- # - identifier: Any name you choose (e.g., agent1, support, salesbot)
23
- # - chatflowId: The UUID of your Flowise chatflow
24
- # - allowedDomains: Comma-separated list of domains where this chat can be embedded
25
- # Note: Wildcard domains (*) are not supported for security reasons
26
- #
27
- # Examples:
28
- # agent1=20db97c6-64c9-4411-bab4-7d6202171600,https://example1.com
29
- # support=1c28f529-a70f-5001-9bc5-4f4c5d03d8c0,https://example2.com,https://another-example2.com
30
- # salesbot=3db97c6-64c9-4411-bab4-7d620217160a,https://sales.example.com
31
-
32
- # Add your chatflows below:
33
- chatflow_1=1d93aaac-ac11-44b8-9646-6ac075fa700d
34
- chatflow_2=
35
-
36
- CHATWOOT_BASE_URL=http://203.145.47.214:8003
1
+ API_HOST=https://kyoceravn.cagent.cmcts.ai
2
+ FLOWISE_API_KEY=your-api-key
3
+
4
+ # Google Analytics Measurement ID (will use default G-MTB5ZRBS1C if not set)
5
+ # GOOGLE_ANALYTICS_ID=
package/.env.example CHANGED
@@ -1,34 +1,44 @@
1
- # ==============================================
2
- # REQUIRED CONFIGURATION
3
- # ==============================================
4
-
5
- # API Host URL (required)
6
- # This should be the URL where your Flowise instance is running
7
- # Example: https://your-flowise-instance.com
8
- API_HOST=
9
-
10
- # Flowise API Key (required)
11
- # Generate this from your Flowise instance settings page
12
- # Example: OxxGE-h_LaH7ZYorStjTOik1XY999RxxoHpCSYl8BXxc
13
- FLOWISE_API_KEY=
14
-
15
- # ==============================================
16
- # CHATFLOWS CONFIGURATION (required)
17
- # ==============================================
18
-
19
- # Format: [identifier]=[chatflowId],[allowedDomain1],[allowedDomain2],...
20
- #
21
- # Each entry consists of:
22
- # - identifier: Any name you choose (e.g., agent1, support, salesbot)
23
- # - chatflowId: The UUID of your Flowise chatflow
24
- # - allowedDomains: Comma-separated list of domains where this chat can be embedded
25
- # Note: Wildcard domains (*) are not supported for security reasons
26
- #
27
- # Examples:
28
- # agent1=20db97c6-64c9-4411-bab4-7d6202171600,https://example1.com
29
- # support=1c28f529-a70f-5001-9bc5-4f4c5d03d8c0,https://example2.com,https://another-example2.com
30
- # salesbot=3db97c6-64c9-4411-bab4-7d620217160a,https://sales.example.com
31
-
32
- # Add your chatflows below:
33
- chatflow_1=
34
- chatflow_2=
1
+ # ==============================================
2
+ # REQUIRED CONFIGURATION
3
+ # ==============================================
4
+
5
+ # API Host URL (required)
6
+ # This should be the URL where your Flowise instance is running
7
+ # Example: https://your-flowise-instance.com
8
+ API_HOST=
9
+
10
+ # Flowise API Key (required)
11
+ # Generate this from your Flowise instance settings page
12
+ # Example: OxxGE-h_LaH7ZYorStjTOik1XY999RxxoHpCSYl8BXxc
13
+ FLOWISE_API_KEY=
14
+
15
+ # ==============================================
16
+ # CHATFLOWS CONFIGURATION (required)
17
+ # ==============================================
18
+
19
+ # Format: [identifier]=[chatflowId],[allowedDomain1],[allowedDomain2],...
20
+ #
21
+ # Each entry consists of:
22
+ # - identifier: Any name you choose (e.g., agent1, support, salesbot)
23
+ # - chatflowId: The UUID of your Flowise chatflow
24
+ # - allowedDomains: Comma-separated list of domains where this chat can be embedded
25
+ # Note: Wildcard domains (*) are not supported for security reasons
26
+ #
27
+ # Examples:
28
+ # agent1=20db97c6-64c9-4411-bab4-7d6202171600,https://example1.com
29
+ # support=1c28f529-a70f-5001-9bc5-4f4c5d03d8c0,https://example2.com,https://another-example2.com
30
+ # salesbot=3db97c6-64c9-4411-bab4-7d620217160a,https://sales.example.com
31
+
32
+ # Add your chatflows below:
33
+ chatflow_1=
34
+ chatflow_2=
35
+
36
+ # ==============================================
37
+ # OPTIONAL CONFIGURATION
38
+ # ==============================================
39
+
40
+ # Google Analytics Measurement ID (optional - defaults to G-MTB5ZRBS1C)
41
+ # Format: G-XXXXXXXXXX (for GA4) or UA-XXXXXXXXX-X (for Universal Analytics)
42
+ # Example: G-ABC123DEF4
43
+ # If not set, will use default: G-MTB5ZRBS1C
44
+ GOOGLE_ANALYTICS_ID=
package/.eslintrc.cjs CHANGED
@@ -1,14 +1,14 @@
1
- module.exports = {
2
- root: true,
3
- extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier', 'plugin:solid/typescript'],
4
- plugins: ['@typescript-eslint', 'solid'],
5
- parser: '@typescript-eslint/parser',
6
- ignorePatterns: ['**/*.md'],
7
- rules: {
8
- '@next/next/no-img-element': 'off',
9
- '@next/next/no-html-link-for-pages': 'off',
10
- 'solid/no-innerhtml': 'off',
11
- '@typescript-eslint/no-namespace': 'off',
12
- '@typescript-eslint/no-explicit-any': 'off'
13
- }
14
- }
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier', 'plugin:solid/typescript'],
4
+ plugins: ['@typescript-eslint', 'solid'],
5
+ parser: '@typescript-eslint/parser',
6
+ ignorePatterns: ['**/*.md'],
7
+ rules: {
8
+ '@next/next/no-img-element': 'off',
9
+ '@next/next/no-html-link-for-pages': 'off',
10
+ 'solid/no-innerhtml': 'off',
11
+ '@typescript-eslint/no-namespace': 'off',
12
+ '@typescript-eslint/no-explicit-any': 'off'
13
+ }
14
+ }
package/.prettierignore CHANGED
@@ -1,3 +1,3 @@
1
- node_modules
2
- build
3
- dist
1
+ node_modules
2
+ build
3
+ dist
package/.prettierrc CHANGED
@@ -1,8 +1,8 @@
1
- {
2
- "semi": true,
3
- "singleQuote": true,
4
- "tabWidth": 2,
5
- "trailingComma": "all",
6
- "printWidth": 150,
7
- "endOfLine": "lf"
8
- }
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "tabWidth": 2,
5
+ "trailingComma": "all",
6
+ "printWidth": 150,
7
+ "endOfLine": "lf"
8
+ }
@@ -0,0 +1,236 @@
1
+ # Google Analytics Integration
2
+
3
+ This chatbot now includes comprehensive Google Analytics tracking to help you understand user interactions and improve your chatbot's performance.
4
+
5
+ ## Setup
6
+
7
+ ### 1. Environment Configuration
8
+
9
+ Add your Google Analytics Measurement ID to your `.env` file:
10
+
11
+ ```env
12
+ # Google Analytics Measurement ID (optional - defaults to G-MTB5ZRBS1C)
13
+ # Format: G-XXXXXXXXXX (for GA4) or UA-XXXXXXXXX-X (for Universal Analytics)
14
+ GOOGLE_ANALYTICS_ID=G-ABC123DEF4
15
+ ```
16
+
17
+ **Note:** If you don't set `GOOGLE_ANALYTICS_ID` in your environment variables, the system will automatically use the default ID: `G-MTB5ZRBS1C`
18
+
19
+ ### 2. Embed Script Configuration
20
+
21
+ When using the embed script, you can optionally include the Google Analytics ID:
22
+
23
+ ```html
24
+ <script type="module">
25
+ import Chatbot from 'https://your-domain.com/web.js';
26
+ Chatbot.init({
27
+ chatflowid: 'your-identifier-here',
28
+ apiHost: 'https://your-domain.com',
29
+ googleAnalyticsId: 'G-ABC123DEF4', // Optional (defaults to G-MTB5ZRBS1C)
30
+ googleAnalyticsConsent: 'auto', // Optional: 'granted', 'denied', or 'auto'
31
+ });
32
+ </script>
33
+ ```
34
+
35
+ **Simplified Usage (using default GA ID):**
36
+
37
+ ```html
38
+ <script type="module">
39
+ import Chatbot from 'https://your-domain.com/web.js';
40
+ Chatbot.init({
41
+ chatflowid: 'your-identifier-here',
42
+ apiHost: 'https://your-domain.com',
43
+ // No googleAnalyticsId needed - will use G-MTB5ZRBS1C automatically
44
+ });
45
+ </script>
46
+ ```
47
+
48
+ ## Fixed Domain Tracking
49
+
50
+ **Important:** All Google Analytics events are tracked to the main domain `https://dvc.cmcts.vn/chatbot` regardless of which website the chatbot is embedded on. This ensures all data is centralized in one GA stream.
51
+
52
+ - **Page Location:** Always `https://dvc.cmcts.vn/chatbot`
53
+ - **Host Website:** Tracked as custom dimension
54
+ - **Stream URL:** `https://dvc.cmcts.vn` (matches GA property configuration)
55
+
56
+ ## Tracked Events
57
+
58
+ The integration automatically tracks the following events:
59
+
60
+ ### 1. Session Events
61
+
62
+ - **`chatbot_opened`**: When the chatbot is first opened
63
+ - **`chatbot_closed`**: When the chatbot is closed
64
+ - **`session_ended`**: When a chat session ends (includes duration and message count)
65
+
66
+ ### 2. User Interaction Events
67
+
68
+ - **`user_message_sent`**: When a user sends a message
69
+
70
+ - `message_length`: Length of the message
71
+ - `has_attachments`: Whether the message includes file attachments
72
+
73
+ - **`starter_prompt_clicked`**: When a user clicks a starter prompt
74
+ - `prompt_text`: The text of the clicked prompt (truncated to 100 characters)
75
+
76
+ ### 3. Bot Response Events
77
+
78
+ - **`bot_response_received`**: When the bot sends a response
79
+ - `response_time_ms`: Time taken to generate the response
80
+ - `message_length`: Length of the bot's response
81
+
82
+ ### 4. Feedback Events
83
+
84
+ - **`feedback_given`**: When a user provides feedback on a message
85
+ - `rating`: 'positive' or 'negative'
86
+ - `message_id`: ID of the message being rated
87
+
88
+ ### 5. File Upload Events
89
+
90
+ - **`file_uploaded`**: When a user uploads a file
91
+ - `file_type`: MIME type of the uploaded file
92
+ - `file_size_bytes`: Size of the file in bytes
93
+
94
+ ### 6. Error Events
95
+
96
+ - **`error_occurred`**: When an error occurs
97
+ - `error_type`: Type of error
98
+ - `error_message`: Error message (truncated to 200 characters)
99
+
100
+ ## Event Structure
101
+
102
+ All events are sent with the following structure:
103
+
104
+ ```javascript
105
+ {
106
+ event_category: 'Chatbot',
107
+ event_label: 'specific_action',
108
+ custom_parameters: {
109
+ chatbot_action: 'action_name',
110
+ // Additional event-specific parameters
111
+ }
112
+ }
113
+ ```
114
+
115
+ ## Google Analytics Dashboard
116
+
117
+ To view your chatbot analytics in Google Analytics:
118
+
119
+ 1. Go to your Google Analytics dashboard
120
+ 2. Navigate to **Events** under **Engagement**
121
+ 3. Look for events with the category **"Chatbot"**
122
+ 4. Create custom reports to analyze:
123
+ - User engagement patterns
124
+ - Most popular starter prompts
125
+ - Average session duration
126
+ - Response times
127
+ - Error rates
128
+
129
+ ## Custom Event Tracking
130
+
131
+ You can also track custom events using the Google Analytics utility:
132
+
133
+ ```javascript
134
+ import { googleAnalytics } from '@/utils/googleAnalytics';
135
+
136
+ // Track a custom event
137
+ googleAnalytics.trackEvent('custom_action', {
138
+ event_category: 'Custom',
139
+ event_label: 'button_click',
140
+ value: 1,
141
+ custom_parameters: {
142
+ button_name: 'help_button',
143
+ },
144
+ });
145
+ ```
146
+
147
+ ## GDPR Compliance & Consent Management
148
+
149
+ ### Consent Modes
150
+
151
+ The integration supports Google's Consent Mode v2 for GDPR compliance:
152
+
153
+ - **`auto`** (default): Privacy-first approach - only analytics tracking, no ads
154
+ - **`granted`**: Full tracking with user consent
155
+ - **`denied`**: No tracking
156
+
157
+ ### Default Privacy Settings
158
+
159
+ When no consent is specified, the integration uses privacy-first defaults:
160
+
161
+ ```javascript
162
+ {
163
+ ad_storage: 'denied', // No advertising cookies
164
+ analytics_storage: 'granted', // Basic analytics only
165
+ ad_user_data: 'denied', // No user data for ads
166
+ ad_personalization: 'denied', // No personalized ads
167
+ functionality_storage: 'granted', // Essential functionality
168
+ personalization_storage: 'denied', // No personalization
169
+ security_storage: 'granted' // Security features enabled
170
+ }
171
+ ```
172
+
173
+ ### Dynamic Consent Management
174
+
175
+ You can update consent dynamically based on user preferences:
176
+
177
+ ```javascript
178
+ import { googleAnalytics } from '@/utils/googleAnalytics';
179
+
180
+ // Grant all consent when user accepts cookies
181
+ googleAnalytics.grantAllConsent();
182
+
183
+ // Deny all consent when user rejects cookies
184
+ googleAnalytics.denyAllConsent();
185
+
186
+ // Custom consent settings
187
+ googleAnalytics.updateConsent({
188
+ analytics_storage: 'granted',
189
+ ad_storage: 'denied',
190
+ });
191
+ ```
192
+
193
+ ## Privacy Considerations
194
+
195
+ - The integration respects user privacy by not tracking personal information
196
+ - Message content is not sent to Google Analytics (only message length)
197
+ - File names are not tracked (only file types and sizes)
198
+ - Error messages are truncated to prevent sensitive information leakage
199
+ - Implements Google's Consent Mode v2 for GDPR compliance
200
+ - Uses privacy-first defaults when no consent is specified
201
+
202
+ ## Troubleshooting
203
+
204
+ ### Google Analytics not loading
205
+
206
+ 1. Verify your `GOOGLE_ANALYTICS_ID` is correctly set in the environment
207
+ 2. Check that the ID format is correct (G-XXXXXXXXXX for GA4)
208
+ 3. Ensure your domain is properly configured in Google Analytics
209
+
210
+ ### Events not appearing
211
+
212
+ 1. Events may take up to 24 hours to appear in Google Analytics
213
+ 2. Use the Real-time reports in GA to see immediate event tracking
214
+ 3. Check browser console for any JavaScript errors
215
+
216
+ ### Testing
217
+
218
+ To test the integration:
219
+
220
+ 1. Open your browser's developer tools
221
+ 2. Go to the Network tab
222
+ 3. Look for requests to `google-analytics.com` or `googletagmanager.com`
223
+ 4. Interact with the chatbot and verify events are being sent
224
+
225
+ ## Benefits
226
+
227
+ With Google Analytics integration, you can:
228
+
229
+ - **Measure engagement**: Track how users interact with your chatbot
230
+ - **Optimize performance**: Identify slow response times and improve them
231
+ - **Improve content**: See which starter prompts are most popular
232
+ - **Monitor errors**: Get notified about issues users encounter
233
+ - **Track conversions**: Measure how the chatbot contributes to your goals
234
+ - **Understand usage patterns**: See when and how often users engage with the chatbot
235
+
236
+ This comprehensive tracking helps you make data-driven decisions to improve your chatbot's effectiveness and user experience.