Analytics
firekitAnalytics wraps Firebase Analytics. All methods are async and return a promise. Analytics is browser-only — calls on the server are silently ignored.
import { firekitAnalytics } from 'svelte-firekit';Log events
Section titled “Log events”// Custom eventawait firekitAnalytics.logEvent('sign_up', { method: 'google' });
// E-commerceawait firekitAnalytics.logEvent('purchase', { value: 29.99, currency: 'USD', items: [{ item_id: 'sku-123', item_name: 'Pro Plan' }],});
// Content engagementawait firekitAnalytics.logEvent('select_content', { content_type: 'article', item_id: 'post-abc',});User identification
Section titled “User identification”// Set the user ID (use your own app's user identifier, not Firebase UID in some cases)await firekitAnalytics.setUserId('user-123');
// Set user propertiesawait firekitAnalytics.setUserProperties({ plan: 'pro', account_type: 'business',});Screen / page views
Section titled “Screen / page views”await firekitAnalytics.logScreenView('Dashboard');await firekitAnalytics.logScreenView('Settings');SvelteKit page tracking
Section titled “SvelteKit page tracking”Track every navigation in SvelteKit by listening to the afterNavigate lifecycle:
<script lang="ts"> import { afterNavigate } from '$app/navigation'; import { firekitAnalytics } from 'svelte-firekit'; import { page } from '$app/stores';
afterNavigate(() => { firekitAnalytics.logEvent('page_view', { page_path: $page.url.pathname, page_title: document.title, }); });</script>Consent mode
Section titled “Consent mode”To comply with GDPR and other privacy regulations, update the consent state before logging events:
// Before user gives consentawait firekitAnalytics.setConsent({ analytics_storage: 'denied', ad_storage: 'denied',});
// After user grants consentawait firekitAnalytics.setConsent({ analytics_storage: 'granted', ad_storage: 'granted',});