1
+ class CustomEvents {
2
+ static triggerService ( serviceName ) {
3
+ gtag ( 'event' , 'use_service' , {
4
+ event_category : 'Service Interactions' ,
5
+ event_label : serviceName ,
6
+ value : 1 ,
7
+ } ) ;
8
+ console . log ( "[GA] Triggered 'use_service' event for service:" , serviceName ) ;
9
+ }
10
+
11
+ static convertServiceError ( serviceName , errorMessage ) {
12
+ gtag ( 'event' , 'service_error' , {
13
+ event_category : 'Service Errors' ,
14
+ event_label : serviceName ,
15
+ value : 1 ,
16
+ error_message : errorMessage ,
17
+ } ) ;
18
+ console . log ( "[GA] Triggered 'service_error' event for service:" , serviceName ) ;
19
+ }
20
+
21
+ static selectServiceTriggered ( serviceName ) {
22
+ gtag ( 'event' , 'select_service' , {
23
+ event_category : 'Service Interactions' ,
24
+ event_label : serviceName ,
25
+ value : 1 ,
26
+ } ) ;
27
+ console . log ( "[GA] Triggered 'select_service' event for service:" , serviceName ) ;
28
+ }
29
+
30
+ static triggerCopyOutput ( ) {
31
+ gtag ( 'event' , 'copy_output' , {
32
+ event_category : 'Output Actions' ,
33
+ event_label : 'Copy Output' ,
34
+ value : 1 ,
35
+ } ) ;
36
+ }
37
+
38
+ static triggerShareOutput ( ) {
39
+ gtag ( 'event' , 'share_output' , {
40
+ event_category : 'Output Actions' ,
41
+ event_label : 'Share Output' ,
42
+ value : 1 ,
43
+ } ) ;
44
+ }
45
+
46
+ static triggerInstallPWA ( ) {
47
+ gtag ( 'event' , 'install_pwa' , {
48
+ event_category : 'PWA Actions' ,
49
+ event_label : 'Install PWA' ,
50
+ value : 1 ,
51
+ } ) ;
52
+ }
53
+
54
+ static triggerAboutUs ( ) {
55
+ gtag ( 'event' , 'about_us' , {
56
+ event_category : 'About Us' ,
57
+ event_label : 'About Us' ,
58
+ value : 1 ,
59
+ } ) ;
60
+ }
61
+ }
62
+
1
63
const SERVICES = [
2
64
{
3
65
title : 'الرسم العربي القديم' ,
@@ -115,6 +177,8 @@ function selectService(functionName, id) {
115
177
116
178
// save last selected service
117
179
localStorage . setItem ( 'lastSelectedService' , functionName ) ;
180
+
181
+ CustomEvents . selectServiceTriggered ( selectedServiceFunction ) ;
118
182
}
119
183
120
184
function convert ( ) {
@@ -123,20 +187,13 @@ function convert() {
123
187
outputTextArea . value = '' ;
124
188
return ;
125
189
}
126
- const url = `https://arabic-services-api-v1.onrender.com/services?method=${ selectedServiceFunction } ` ;
127
- fetch ( url , {
128
- method : 'POST' ,
129
- body : JSON . stringify ( { input : inputText } ) ,
130
- headers : { 'Content-Type' : 'application/json' } ,
131
- } )
132
- . then ( ( response ) => response . text ( ) )
133
- . then ( ( data ) => {
134
- outputTextArea . value = data ;
135
- } )
136
- . catch ( ( error ) => {
137
- console . error ( 'Error:' , error ) ;
138
- outputTextArea . value = ArabicServices [ selectedServiceFunction ] ( inputText ) ;
139
- } ) ;
190
+ try {
191
+ outputTextArea . value = ArabicServices [ selectedServiceFunction ] ( inputText ) ;
192
+ CustomEvents . triggerService ( selectedServiceFunction ) ;
193
+ } catch ( error ) {
194
+ console . error ( error ) ;
195
+ CustomEvents . convertServiceError ( selectedServiceFunction , error . message ) ;
196
+ }
140
197
}
141
198
142
199
document . addEventListener ( 'DOMContentLoaded' , function ( ) {
@@ -175,6 +232,7 @@ slider.addEventListener('mouseleave', mouseleave);
175
232
slider . addEventListener ( 'mouseup' , ( ) => {
176
233
if ( ! isDrag ) {
177
234
selectService ( selectedServiceFunction , selectedSlideId ) ;
235
+ console . log ( 'when mouseup' ) ;
178
236
}
179
237
mouseleave ( ) ;
180
238
} ) ;
@@ -205,6 +263,8 @@ function copyOutput() {
205
263
showConfirmButton : false ,
206
264
timer : 1500 ,
207
265
} ) ;
266
+
267
+ CustomEvents . triggerCopyOutput ( ) ;
208
268
}
209
269
210
270
// --------------------- Share -----------------------------
@@ -214,6 +274,8 @@ function shareOutput() {
214
274
return ;
215
275
}
216
276
277
+ CustomEvents . triggerShareOutput ( ) ;
278
+
217
279
// Check if the Web Share API is available
218
280
if ( navigator . share ) {
219
281
navigator
@@ -275,6 +337,8 @@ function downloadHandlerForPWA() {
275
337
}
276
338
deferredPrompt = null ;
277
339
} ) ;
340
+
341
+ CustomEvents . triggerInstallPWA ( ) ;
278
342
}
279
343
280
344
window . addEventListener ( 'appinstalled' , ( ) => {
@@ -315,6 +379,8 @@ function promptInstallPWA() {
315
379
// --------------------- About Us -----------------------------
316
380
317
381
function showAboutUs ( ) {
382
+ CustomEvents . triggerAboutUs ( ) ;
383
+
318
384
Swal . fire ( {
319
385
title : 'من نحن' ,
320
386
width : '90%' ,
0 commit comments