diff --git a/frog/services/telemetry.py b/frog/services/telemetry.py index 03c9b1b..bed7179 100644 --- a/frog/services/telemetry.py +++ b/frog/services/telemetry.py @@ -26,5 +26,8 @@ def capture(self, event: str, props: Any = None): if self.posthog and self.is_active: self.posthog.capture(self.installation_id, event, props) + def capture_page_view(self, page_name: str): + self.posthog.capture(self.installation_id, '$pageview', {'$current_url': page_name}) + telemetry = TelemetryService() diff --git a/frog/widgets/extracted_page.py b/frog/widgets/extracted_page.py index cfd7e16..f6cc41e 100644 --- a/frog/widgets/extracted_page.py +++ b/frog/widgets/extracted_page.py @@ -31,12 +31,10 @@ from frog.config import RESOURCE_PREFIX from frog.gobject_worker import GObjectWorker -# from frog.language_manager import language_manager from frog.services.share_service import ShareService +from frog.services.telemetry import telemetry from frog.services.tts import ttsservice, TTSService from frog.settings import Settings -# from frog.types.language_item import LanguageItem -# from frog.widgets.language_popover import LanguagePopover from frog.widgets.share_row import ShareRow @@ -87,10 +85,8 @@ def do_hiding(self) -> None: self.buffer.set_text("") self.emit("go-back", 1) - # def do_showing(self) -> None: - # self.lang_combo.set_label( - # language_manager.get_language(self.settings.get_string("active-language")) - # ) + def do_showing(self) -> None: + telemetry.capture_page_view('extracted') @GObject.Property(type=str) def extracted_text(self) -> str: diff --git a/frog/widgets/language_popover.py b/frog/widgets/language_popover.py index a5a3b2b..007c5d6 100644 --- a/frog/widgets/language_popover.py +++ b/frog/widgets/language_popover.py @@ -71,6 +71,8 @@ def __init__(self): # self.populate_model() self.bind_model() + self.connect('show', lambda x: telemetry.capture_page_view('language_popover')) + def bind_model(self): self.filter = Gtk.CustomFilter() self.filter.set_filter_func(self._on_language_filter) diff --git a/frog/widgets/preferences_general_page.py b/frog/widgets/preferences_general_page.py index 8467645..e2c7100 100644 --- a/frog/widgets/preferences_general_page.py +++ b/frog/widgets/preferences_general_page.py @@ -25,12 +25,12 @@ # holders shall not be used in advertising or otherwise to promote the sale, # use or other dealings in this Software without prior written # authorization. -import posthog from gi.repository import Gtk, Adw, Gio from loguru import logger from frog.config import RESOURCE_PREFIX from frog.language_manager import language_manager +from frog.services.telemetry import telemetry from frog.settings import Settings @@ -61,7 +61,7 @@ def __init__(self): self.extra_language_combo.connect('notify::selected-item', self._on_extra_language_changed) def do_show(self, *args, **kwargs): - posthog.capture('', 'preferences general page opened') + telemetry.capture_page_view('preferences_general') def _on_extra_language_changed(self, combo_row: Adw.ComboRow, _param): lang_name = combo_row.get_selected_item().get_string() diff --git a/frog/widgets/preferences_languages_page.py b/frog/widgets/preferences_languages_page.py index 0f02dd0..9615865 100644 --- a/frog/widgets/preferences_languages_page.py +++ b/frog/widgets/preferences_languages_page.py @@ -32,6 +32,7 @@ from frog.config import RESOURCE_PREFIX from frog.language_manager import language_manager +from frog.services.telemetry import telemetry from frog.settings import Settings from frog.types.language_item import LanguageItem from frog.widgets.language_row import LanguageRow @@ -74,6 +75,9 @@ def __init__(self): self.check_connection() + def do_show(self): + telemetry.capture_page_view('preferences_languages') + def check_connection(self): # Check for access to GitHub if not Gio.NetworkMonitor.get_default().can_reach(Gio.NetworkAddress.new('raw.githubusercontent.com', 443)): diff --git a/frog/widgets/preferences_window.py b/frog/widgets/preferences_window.py index 55c9ca1..d5e48a6 100644 --- a/frog/widgets/preferences_window.py +++ b/frog/widgets/preferences_window.py @@ -29,6 +29,7 @@ from gi.repository import Gtk, Adw, GObject from frog.config import RESOURCE_PREFIX +from frog.services.telemetry import telemetry from frog.settings import Settings from frog.widgets.preferences_general_page import PreferencesGeneralPage from frog.widgets.preferences_languages_page import PreferencesLanguagesPage @@ -45,6 +46,8 @@ def __init__(self, settings: Settings, parent: Adw.Window = None): super().__init__() self.set_transient_for(parent) + self.connect('show', lambda x: telemetry.capture_page_view('preferences')) + class LanguageItem(GObject.GObject): title: str diff --git a/frog/widgets/welcome_page.py b/frog/widgets/welcome_page.py index 7e2e184..f2c68cb 100644 --- a/frog/widgets/welcome_page.py +++ b/frog/widgets/welcome_page.py @@ -31,6 +31,7 @@ from frog.config import RESOURCE_PREFIX, APP_ID from frog.language_manager import language_manager +from frog.services.telemetry import telemetry from frog.types.language_item import LanguageItem from frog.widgets.language_popover import LanguagePopover @@ -58,6 +59,9 @@ def __init__(self): language_manager.get_language(self.settings.get_string("active-language")) ) + def do_showing(self): + telemetry.capture_page_view('welcome') + def _on_language_changed(self, _: LanguagePopover, language: LanguageItem): self.lang_combo.set_label(language.title) self.settings.set_string("active-language", language.code) diff --git a/pyproject.toml b/pyproject.toml index be57b7e..5538c87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,10 @@ [tool.ruff] # Decrease the maximum line length to 79 characters. line-length = 120 + +[tool.ruff.format] +quote-style = "single" +indent-style = "tab" +docstring-code-format = true +docstring-code-format = true +docstring-code-line-length = 20 \ No newline at end of file