Skip to content

fix(analytics): E-01 to E-06 install id, install event, login prompt events, translation dedupe - #62

Merged
navidshad merged 5 commits into
devfrom
analytics-fixes/extension-E-01-to-E-06
Oct 16, 2026
Merged

navidshad merged 5 commits into
devfrom
analytics-fixes/extension-E-01-to-E-06

Conversation

@navidshad

@navidshad navidshad commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

All extension rows of the analytics fixes in one PR, to cut deploy time. It replaces #58, #59, #60 and #61 (same commits, cherry-picked onto the latest dev).

Why: subturtle-doc docs/tech/analytics-fixes-implementation.md (rows E-01 to E-06; E-07 is not in this round).

E-01: send the install id with server calls

  • translateWithContext (simple and detailed), translationAdvice and createPhrase now send deviceId. This is the install's analytics id (analyticsAnonymousId in chrome.storage.local). userId is still sent for old servers.
  • New helper src/common/helper/install-id.ts reads the id, or creates it with the same key and format as mixpanel.ts. Each call waits for the stored id, so it never sends an empty value. It reads the id on every call, so after logout it sends the new one.

E-05: send the trigger with each translation

  • caption: whole-caption translation (Netflix and the support template)
  • word: a hovered caption word
  • selection: the Nibble selection popup
  • detail: the word detail panel
  • definition is in the type for the server contract, but no caller uses it (Definition.vue no longer exists).

E-02: install and update events, welcome page

  • chrome.runtime.onInstalled sends extension_installed or extension_updated (with previous_version) on the install id.
  • On a first install it opens https://subturtle.app/?install_id=<id>&utm_source=extension&utm_medium=install.
  • The service worker has no window, so it sends the event with fetch to Mixpanel's /track (through MIXPANEL_API_HOST). A failure never throws.
  • The welcome page opens only for Web Store installs. Unpacked builds (dev, CI) send the event but do not open the site, so they do not count fake installs on the landing page.

E-03: "Login to save" prompt and login results

  • save-login-prompt_viewed (once per word view when the button shows) and save-login-prompt_clicked.
  • user_logged-in gains source (save_prompt, practice, popup).
  • New login_failed with source and reason (window_closed, google_error, server_error).
  • The login runs in its own window, so the source goes on its URL (#/login?source=…). practice-now_login-clicked is kept.
  • Small fix: a Google login whose server reply has no token no longer stores an empty token. It counts as login_failed (server_error).

E-04: share translations already in flight

  • Two identical calls made at the same time send one request and get the same answer. The entry is removed when the request settles. Failures are not cached.
  • The in-flight entry is registered before the install id is read (E-01), so a second call during that read also shares the request.

E-06: translate each caption once

  • New helper src/subtitle/helpers/caption-translation-gate.ts, used by both caption components. With "translate whole caption" on, it waits about 150 ms for the caption to settle and skips a caption that is already translated on screen. A failed caption can be sent again.

How tested

  • New unit tests: translate-analytics-args, install-tracking, save-login-prompt, login-analytics, caption-translation-gate, plus in-flight cases in translate.service.
  • yarn typecheck: clean.
  • yarn test: 45 files, 398 tests pass.
  • yarn build: OK.
  • yarn test:e2e: 22 of 22 pass with CI's Mixpanel stub settings. (With a real Mixpanel host in the local env, one analytics test cannot see its stub requests; that is a local setup issue, not a bug.)
  • The repo has no lint script.
  • Not checked on real Netflix (the caption path cannot run in our test setup).

Dependencies

🤖 Generated with Claude Code

navidshad and others added 5 commits October 16, 2026 19:13
… page

- chrome.runtime.onInstalled now tracks extension_installed (reason
  install) or extension_updated (with previous_version) on the install's
  analytics id. The id is created when missing, with the same key and
  format as plugins/mixpanel.ts (new helper common/helper/install-id.ts).
- The service worker has no window or document, so mixpanel-browser is
  not loaded there. The events go to Mixpanel's /track endpoint with
  fetch, through MIXPANEL_API_HOST, in the same shape mixpanel-browser
  sends. A failed request never throws.
- On install it opens
  https://subturtle.app/?install_id=<id>&utm_source=extension&utm_medium=install
  for the landing page (D-01). Unpacked builds (local dev, CI e2e) skip
  the tab, so they do not open the site or count fake installs.
- Tests: tests/install-tracking.test.ts.

Work list: subturtle-doc docs/tech/analytics-fixes-implementation.md
Pairs with landing D-01 (codebridger/subturtle-dashboard-app#144).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…te each caption once

- E-04: TranslateService keeps a map of requests in flight by cache key.
  An identical call made before the first one answers waits for it and
  gets the same answer, so only one request goes out. The entry is removed
  when the request settles; a failure reaches every waiting caller and is
  never cached.
- E-06: new src/subtitle/helpers/caption-translation-gate.ts. With
  "translate whole caption" on, the Netflix and support-template caption
  components wait about 150 ms for the caption to settle, then send it
  only when the joined text differs from the caption already translated
  on screen. A failed caption can be sent again. Turning the option on
  still translates at once.
- Tests: in-flight cases in tests/translate.service.test.ts, new
  tests/caption-translation-gate.test.ts.

Work list: subturtle-doc docs/tech/analytics-fixes-implementation.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Word card: save-login-prompt_viewed fires once per word view when
  "Login to save this phrase" shows (a new word or a new view resets it).
  Clicking it sends save-login-prompt_clicked.
- OpenLoginWindowMessage carries a source (save_prompt, practice, popup).
  The background puts it on the login window URL
  (popup.html#/login?source=...), and LoginView reads it. No source means
  the toolbar popup.
- user_logged-in gains source. New login_failed with source and reason:
  window_closed (Google consent window closed), google_error (no Google
  token), server_error (our server failed or sent no token, or the
  password login was rejected).
- The Google flow no longer stores an empty token when the server reply
  has none; it counts as a failed login.
- practice-now_login-clicked is kept.
- Tests: tests/save-login-prompt.test.ts, tests/login-analytics.test.ts.

Work list: subturtle-doc docs/tech/analytics-fixes-implementation.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…E-01

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ation calls

- New helper src/common/helper/install-id.ts reads the install's analytics
  id (analyticsAnonymousId in chrome.storage.local), or creates it with the
  same key and format as plugins/mixpanel.ts. It waits for storage, so a
  call never sends an empty id, and it reads on each call, so it follows
  the new id after logout.
- translateWithContext (simple and detailed), translationAdvice and
  createPhrase now send deviceId. userId stays for old servers.
- Each translation caller sends trigger: caption (both caption
  components), word (marker store, hovered caption word), selection
  (selection popup), detail (word detail). "definition" is in the type for
  the server contract; no caller uses it today (Definition.vue is gone).
- Tests: tests/translate-analytics-args.test.ts.

Work list: subturtle-doc docs/tech/analytics-fixes-implementation.md
Pairs with server B-01 / B-03. The server ignores unknown args today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.17.0-dev.8 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant