From 3d9338d00618b1867a7866b747cafca012ff9902 Mon Sep 17 00:00:00 2001 From: Andrey Maksimov Date: Wed, 10 Jan 2024 10:27:30 +0300 Subject: [PATCH] Add PostHog --- flatpak/com.github.tenderowl.frog.json | 1 + flatpak/python3-posthog.json | 54 ++++++++++++++++++++++++++ frog/main.py | 2 + frog/services/posthog.py | 3 ++ frog/widgets/language_popover.py | 2 + 5 files changed, 62 insertions(+) create mode 100644 flatpak/python3-posthog.json create mode 100644 frog/services/posthog.py diff --git a/flatpak/com.github.tenderowl.frog.json b/flatpak/com.github.tenderowl.frog.json index a4e7878..79fae55 100644 --- a/flatpak/com.github.tenderowl.frog.json +++ b/flatpak/com.github.tenderowl.frog.json @@ -33,6 +33,7 @@ "python3-pytesseract.json", "python3-pyzbar.json", "python3-gTTS.json", + "python3-posthog.json", { "name" : "frog", "builddir" : true, diff --git a/flatpak/python3-posthog.json b/flatpak/python3-posthog.json new file mode 100644 index 0000000..6dbd082 --- /dev/null +++ b/flatpak/python3-posthog.json @@ -0,0 +1,54 @@ +{ + "name": "python3-posthog", + "buildsystem": "simple", + "build-commands": [ + "pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"posthog\" --no-build-isolation" + ], + "sources": [ + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/df/73/b6e24bd22e6720ca8ee9a85a0c4a2971af8497d8f3193fa05390cbd46e09/backoff-2.2.1-py3-none-any.whl", + "sha256": "63579f9a0628e06278f7e47b7d7d5b6ce20dc65c5e96a6f3ca99a6adca0396e8" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/64/62/428ef076be88fa93716b576e4a01f919d25968913e817077a386fcbe4f42/certifi-2023.11.17-py3-none-any.whl", + "sha256": "e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/63/09/c1bc53dab74b1816a00d8d030de5bf98f724c52c1635e07681d312f20be8/charset-normalizer-3.3.2.tar.gz", + "sha256": "f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl", + "sha256": "c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/9a/67/7e8406a29b6c45be7af7740456f7f37025f0506ae2e05fb9009a53946860/monotonic-1.6-py2.py3-none-any.whl", + "sha256": "68687e19a14f11f26d140dd5c86f3dba4bf5df58003000ed467e0e2a69bca96c" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/3b/82/441cb77a43499661228048dcd0d21e0ae3235b442d0f1b9b606e29c2a5ed/posthog-3.1.0-py2.py3-none-any.whl", + "sha256": "acd033530bdfc275dce5587f205f62378991ecb9b7cd5479e79c7f4ac575d319" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/36/7a/87837f39d0296e723bb9b62bbb257d0355c7f6128853c78955f57342a56d/python_dateutil-2.8.2-py2.py3-none-any.whl", + "sha256": "961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/70/8e/0e2d847013cb52cd35b38c009bb167a1a26b2ce6cd6965bf26b47bc0bf44/requests-2.31.0-py3-none-any.whl", + "sha256": "58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f" + }, + { + "type": "file", + "url": "https://files.pythonhosted.org/packages/96/94/c31f58c7a7f470d5665935262ebd7455c7e4c7782eb525658d3dbf4b9403/urllib3-2.1.0-py3-none-any.whl", + "sha256": "55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3" + } + ] +} \ No newline at end of file diff --git a/frog/main.py b/frog/main.py index 1652757..29e4b95 100644 --- a/frog/main.py +++ b/frog/main.py @@ -35,6 +35,7 @@ from frog.config import RESOURCE_PREFIX, APP_ID from frog.language_manager import language_manager from frog.services.clipboard_service import clipboard_service +from frog.services.posthog import posthog from frog.services.screenshot_service import ScreenshotService from frog.settings import Settings from frog.window import FrogWindow @@ -125,6 +126,7 @@ def on_preferences(self, _action, _param) -> None: self.get_active_window().show_preferences() def on_github_star(self, _action, _param) -> None: + posthog.capture('github_star', 'github_star_activated') launcher: Gtk.UriLauncher = Gtk.UriLauncher() launcher.set_uri('https://github.com/TenderOwl/Frog') launcher.launch(callback=self._on_github_star) diff --git a/frog/services/posthog.py b/frog/services/posthog.py new file mode 100644 index 0000000..687de63 --- /dev/null +++ b/frog/services/posthog.py @@ -0,0 +1,3 @@ +from posthog import Posthog + +posthog = Posthog(project_api_key='phc_mggXA1JbzpJR95H9RO5yNVIh6kVDliVjD5hOjiaXkj6', host='https://us.posthog.com') diff --git a/frog/widgets/language_popover.py b/frog/widgets/language_popover.py index 4c718c5..0341dce 100644 --- a/frog/widgets/language_popover.py +++ b/frog/widgets/language_popover.py @@ -30,6 +30,7 @@ from frog.config import RESOURCE_PREFIX from frog.language_manager import language_manager +from frog.services.posthog import posthog from frog.settings import Settings from frog.types.language_item import LanguageItem from frog.widgets.language_popover_row import LanguagePopoverRow @@ -102,6 +103,7 @@ def _on_language_activate(self, _: Gtk.ListBox, row: LanguagePopoverRow): self.emit('language-changed', item) self.active_language = item.code language_manager.active_language = item + posthog.capture(item.code, 'language-activated') self.popdown() @Gtk.Template.Callback()