textgrab / extension

Chrome Extension
1 stars 1 forks source link

feat: add google analytics #42

Closed sriharivishnu closed 2 years ago

sriharivishnu commented 2 years ago

Google Analytics

Originally, I planned to use their libraries, either ga.js, analytics.js, or gtag.js, in order to easily send analytics. However, after experimentation, all three of those methods were written for events in a web page and not a service workers. In order for our analytics to not interfere with analytics from other sites (since they all use the same window "message queue"), I have to put the analytics logic in the background service worker.

Previously, this was much easier since you could define a background.html file. However, with Manifest V3 (which google now requires), background pages have been replaced with service workers, which cannot have an html file.

So, finally, I ended up writing the analytics logic and passing it to google analytics via their API. I could not use the latest version of their API (GA4) since that also relied on the presence of a ClientID (requires gtag.js, which requires again a webpage), and instead used Universal Analytics

This PR

This PR sets up some initial analytics events. Here's a summary:

category action label description
ui_result process rect_accuracy Mean Squared error of rectangle width accuracy
ui_event cancel_selection ESC user cancelled selection of an element with the escape key
ui_event cancel_selection window_click user clicked an element which was not supported, cancelling selection
ui_event target_found VIDEO/IMG a target image/video was found successfully
ui_event drag_menu ; where the menu was dragged to as a relative % from top left of the target
ui_event recapture_interval interval between a capture/recapture and the next recapture
buttons menu copy_all the copy all button in the menu clicked
buttons menu recapture recapture button the menu clicked
buttons menu cancel_selection cancel selection button in menu clicked
buttons capture_btn capture the capture button in the popup is clicked
buttons popup settings_btn settings button was clicked from the popup
buttons options restore_defaults_btn Restore defaults button in options
buttons options save_settings_btn Save settings button
shortcuts alt_c capture the shortcut ALT-C / OPT-C was used
image get_base64_data_success Video/Img we were able to extract data from an image
image get_base64_data_error Error when getting data from image
API process duration Time in ms to process image
API api_error API error
API api_success get_text_rects # of rectangles
app_updates install user has first installed the extension
app_updates update user has updated the extension
options highlightColor <highlight-colour user has switched the highlight colour