Skip to content

Commit

Permalink
Fix: GA4 側に送信されるタイトルにバージョン情報が含まれないことがあるのを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukumijima committed Dec 31, 2024
1 parent bd8862a commit eb522c2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,6 @@ onMounted(async () => {
}
// Google アナリティクスに page_view イベントを送信する
analytics.trackEvent("page_view");
void analytics.trackEvent("page_view");
});
</script>
2 changes: 1 addition & 1 deletion src/components/Talk/ToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ registerHotkeyWithCleanup({
});
const trackToolbarAction = (actionName: string) => {
useAnalytics().trackEvent("aisp_toolbar_button_click", {
void useAnalytics().trackEvent("aisp_toolbar_button_click", {
action_name: actionName,
});
};
Expand Down
7 changes: 6 additions & 1 deletion src/composables/useAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function useAnalytics() {
enabled.value = false;
};

const trackEvent = (
const trackEvent = async (
eventName: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
eventParameters?: Record<string, any>,
Expand All @@ -156,6 +156,11 @@ export function useAnalytics() {
const client_id = getOrCreateClientId();
const { session_id, session_count } = getOrCreateSession();
if (shouldInitializeGA4) {
// 新規セッション取得前に document.title にタイトルを設定しておくことで、タイミング次第では
// テレメトリで送信されるタイトルにバージョン情報が含まれなくなる ("AivisSpeech" のみになってしまう) ことを防ぐ
// document.title への今後の変更は GA4MP 側には反映されない
const appInfo = await window.backend.getAppInfos();
window.document.title = `AivisSpeech ${appInfo.version}`;
ga4instance = ga4mp([GA4_MEASUREMENT_ID], {
debug: true,
non_personalized_ads: true,
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useDialogAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useDialogAnalytics(
watch(
() => isOpen.value,
(newValue) => {
analytics.trackEvent("aisp_dialog_state_change", {
void analytics.trackEvent("aisp_dialog_state_change", {
dialog_name: dialogName,
dialog_state: newValue ? "opened" : "closed",
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/ipcMessageReceiverPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const ipcMessageReceiver: Plugin = {
DETECT_RESIZED: debounce(
(_, { width, height }: { width: number; height: number }) => {
// window.dataLayer?.push({ event: "windowResize", width, height });
useAnalytics().trackEvent("aisp_window_resize", { width, height });
void useAnalytics().trackEvent("aisp_window_resize", { width, height });
},
300,
),
Expand Down
4 changes: 2 additions & 2 deletions src/store/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export const settingStore = createPartialStore<SettingStoreTypes>({
});
*/
if (acceptRetrieveTelemetry !== state.acceptRetrieveTelemetry) {
useAnalytics().trackEvent("aisp_accept_retrieve_telemetry_update", {
void useAnalytics().trackEvent("aisp_accept_retrieve_telemetry_update", {
acceptRetrieveTelemetry: acceptRetrieveTelemetry == "Accepted",
});
}
Expand All @@ -289,7 +289,7 @@ export const settingStore = createPartialStore<SettingStoreTypes>({
});
*/
if (acceptTerms !== state.acceptTerms) {
useAnalytics().trackEvent("aisp_accept_terms_update", {
void useAnalytics().trackEvent("aisp_accept_terms_update", {
acceptTerms: acceptTerms == "Accepted",
});
}
Expand Down

0 comments on commit eb522c2

Please sign in to comment.