Skip to content

Commit

Permalink
Add page view events
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Maksimov committed Jan 22, 2024
1 parent 0863da3 commit 86f49b5
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions frog/services/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 3 additions & 7 deletions frog/widgets/extracted_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions frog/widgets/language_popover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions frog/widgets/preferences_general_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions frog/widgets/preferences_languages_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down
3 changes: 3 additions & 0 deletions frog/widgets/preferences_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions frog/widgets/welcome_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 86f49b5

Please sign in to comment.