-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
When integrating tauri-plugin-aptabase
with Tauri v2 applications, developers may encounter a TypeError: window.__TAURI_IPC__ is not a function
error when calling trackEvent
from the frontend.
The Problem
The current version of tauri-plugin-aptabase
does not use the latest version of the Tauri Core API from @tauri-apps/api/core
. This results in the error:
TypeError: window.__TAURI_IPC__ is not a function
Looking at the source code, the plugin uses:
import { invoke } from '@tauri-apps/api/core'
export async function trackEvent(name: string, props?: Props): Promise<void> {
await invoke<string>('plugin:aptabase|track_event', { name, props });
}
If you still encounter the IPC error, you can bypass the plugin's TypeScript wrapper and invoke the command directly (make your own trackEvent function with the latest invoke
instead of importing it from the package):
import { invoke } from '@tauri-apps/api/core';
export async function trackEvent(
name: string,
props?: {
[key: string]: string | number;
},
): Promise<void> {
await invoke<string>('plugin:aptabase|track_event', { name, props });
}
export const analytics = {
async logEvent(event: Event): Promise<void> {
try {
const { type, ...properties } = event;
await trackEvent(type, properties);
} catch (error) {
// Silently fail - analytics should never break the app
console.debug('[Analytics] Event logging failed:', error);
}
},
};
Then use it in your components:
import { analytics } from '$lib/services/analytics';
// Log an event
await analytics.logEvent({
type: 'button_clicked',
button_name: 'submit'
});
Metadata
Metadata
Assignees
Labels
No labels