Skip to content

Commit d75bc62

Browse files
authored
Merge pull request #31 from codebridger/CU-86exvrzy8_Close-analytics-gaps-against-docsmetrics-convention-names-missing-events-Stripe-webhook-lifecycle_Navid-Shad
Title: Align Analytics Events with Documentation and Fix Unit Test Imports #86exvrzy8
2 parents 0ae90b5 + c0eebf4 commit d75bc62

10 files changed

Lines changed: 26 additions & 5 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ static/key-file.json
88
.npmrc
99
/.claude
1010
/playwright-report
11-
/test-results
11+
/test-results
12+
.agent

src/common/services/translate.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { Dictionary } from "../types/general.type";
77

88
import proxy from "./proxy.service";
9-
import { functionProvider } from "@modular-rest/client";
9+
import { functionProvider, authentication } from "@modular-rest/client";
1010
import {
1111
Chunk,
1212
LanguageLearningData,
@@ -132,6 +132,8 @@ export class TranslateService {
132132
targetLanguage: this.languageTitle,
133133
phrase: text,
134134
context: context || "",
135+
// For the server-side translation_requested analytics event.
136+
userId: authentication.user?.id,
135137
},
136138
});
137139

@@ -169,6 +171,8 @@ export class TranslateService {
169171
targetLanguage: this.languageTitle,
170172
phrase: text,
171173
context: context || "",
174+
// For the server-side translation_requested analytics event.
175+
userId: authentication.user?.id,
172176
},
173177
});
174178

src/console-crane/components/Definition.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export default defineComponent({
139139
});
140140
});
141141
142-
analytic.track("Definition translated");
142+
analytic.track("definition_translated");
143143
},
144144
},
145145
});

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function start() {
8989
.then((_) => {
9090
registerGlobalEvents();
9191
})
92-
.catch((_) => analytic.track("Error on initiating"));
92+
.catch((_) => analytic.track("extension_init-failed"));
9393
}
9494

9595
//

src/popup/views/LoginView.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ import {
136136
StoreUserTokenMessage,
137137
} from "../../common/types/messaging";
138138
import { sendMessage, sendMessageToTabs } from "../../common/helper/massage";
139+
import { analytic } from "../../plugins/mixpanel";
139140
import { get } from "../helper/http";
140141
import { joinToBaseUrl } from "../../common/helper/url";
141142
import {
@@ -240,6 +241,9 @@ async function handleTokenLogin(token: string) {
240241
await sendMessage(message);
241242
sendMessageToTabs(message);
242243
await loginWithLastSession();
244+
// Fired only on an explicit login from this view — session restores on
245+
// startup do not pass through here.
246+
analytic.track("user_logged-in");
243247
}
244248
245249
function launchWebAuthFlow(authURL) {

src/subtitle/_support-template/components/Subtitle.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export default defineComponent({
186186
hoveredWord(value) {
187187
if (value.length) {
188188
this.translateWord(value);
189-
analytic.track("Word hovered", { word: value });
189+
analytic.track("phrase_hovered", { word: value });
190190
}
191191
},
192192
},

src/subtitle/components/specific/Word.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ function onMouseLeave(e: MouseEvent) {
9696
}
9797
9898
function OpenWordDetail() {
99+
analytic.track("phrase_clicked", {
100+
word:
101+
markerStore.words.length > 1
102+
? markerStore.selectedPhrase
103+
: props.modelValue,
104+
platform: window.location.hostname,
105+
});
99106
if (markerStore.words.length > 1) {
100107
emitOpen({
101108
page: "word-detail",

tests/nibble-surface.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ vi.mock("../src/nibble/composables/useTextSelection", async () => {
3030
// the child stub doesn't trigger a real fetch chain just by importing.
3131
vi.mock("@modular-rest/client", () => ({
3232
functionProvider: { run: vi.fn() },
33+
authentication: { user: { id: "test-user-id" } },
3334
}));
3435

3536
import NibbleSurface from "../src/nibble/components/NibbleSurface.vue";

tests/selection-popup.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createTestingPinia } from "@pinia/testing";
66
// network layer so a stray click in another test can't fire a real request.
77
vi.mock("@modular-rest/client", () => ({
88
functionProvider: { run: vi.fn() },
9+
authentication: { user: { id: "test-user-id" } },
910
}));
1011

1112
import SelectionPopup from "../src/nibble/components/SelectionPopup.vue";

tests/translate.service.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ vi.mock("@modular-rest/client", () => ({
55
functionProvider: {
66
run: vi.fn(),
77
},
8+
// translate.service reads authentication.user?.id to attach a userId for the
9+
// server-side translation_requested event.
10+
authentication: { user: { id: "test-user-id" } },
811
}));
912

1013
import { TranslateService } from "../src/common/services/translate.service";

0 commit comments

Comments
 (0)