Skip to content

fix(analytics): E-01 E-05 send the install id and trigger with translation calls - #58

Closed
navidshad wants to merge 1 commit into
devfrom
analytics-fixes/E-01-E-05-device-id-and-trigger
Closed

navidshad wants to merge 1 commit into
devfrom
analytics-fixes/E-01-E-05-device-id-and-trigger

Conversation

@navidshad

Copy link
Copy Markdown
Collaborator

What

  • E-01: Translation calls now send deviceId. This is the install's analytics id (analyticsAnonymousId in chrome.storage.local). It goes with translateWithContext (simple and detailed), translationAdvice and createPhrase. These are the calls where the server fires an analytics event or uses credits. userId is still sent, for old servers.
  • E-05: Each translation call sends trigger:
    • caption: whole-caption translation (Netflix and the support template)
    • word: a hovered caption word (marker store and the template)
    • selection: the Nibble selection popup
    • detail: the word detail panel
    • definition is in the type for the server contract. No caller uses it today, because Definition.vue no longer exists.
  • New helper src/common/helper/install-id.ts. It reads the id from storage, or creates it with the same key and format as src/plugins/mixpanel.ts. mixpanel.ts now imports the key and the id maker from it.

Why

Server events could not be joined to the extension's analytics id. Logged-out users all shared one anonymous account id. The server also could not tell what asked for a translation. Work list: subturtle-doc docs/tech/analytics-fixes-implementation.md (rows E-01, E-05).

The id is loaded from storage asynchronously. So each call waits for the stored id instead of sending an empty value. It reads the id on every call, so after logout (which makes a new id) the next call sends the new one. Two calls at the same time on the very first page share one read, so they do not create two different ids.

How tested

  • New unit tests: tests/translate-analytics-args.test.ts (deviceId and trigger for every call, id created when missing, no empty id).
  • yarn typecheck: clean.
  • yarn test: 41 files, 368 tests pass.
  • yarn build: OK.
  • The repo has no lint script.

Dependencies

  • Pairs with server rows B-01 and B-03 (subturtle-dashboard-app). The server ignores unknown args today, so this PR is safe to merge first.

🤖 Generated with Claude Code

…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>
@navidshad

Copy link
Copy Markdown
Collaborator Author

Replaced by #62, which combines all extension rows (E-01 to E-06) into one PR.

@navidshad navidshad closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant