svelte-firekit 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Collection.svelte +49 -77
- package/dist/components/Doc.svelte +140 -0
- package/dist/components/{Ddoc.svelte.d.ts → Doc.svelte.d.ts} +3 -3
- package/dist/components/upload-task.svelte +1 -1
- package/dist/firebase.d.ts +9 -0
- package/dist/firebase.js +24 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/services/analytics.d.ts +272 -0
- package/dist/services/analytics.js +476 -0
- package/dist/services/auth.d.ts +26 -21
- package/dist/services/auth.js +93 -22
- package/dist/services/collection.svelte.d.ts +1 -14
- package/dist/services/collection.svelte.js +10 -85
- package/dist/services/index.d.ts +9 -0
- package/dist/services/index.js +10 -0
- package/dist/services/mutations.d.ts +5 -37
- package/dist/services/mutations.js +43 -140
- package/dist/services/presence.svelte.d.ts +1 -22
- package/dist/services/presence.svelte.js +1 -101
- package/dist/types/analytics.d.ts +84 -0
- package/dist/types/analytics.js +6 -0
- package/dist/types/auth.d.ts +65 -7
- package/dist/types/collection.d.ts +0 -25
- package/dist/types/firebase.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/mutations.d.ts +0 -22
- package/dist/types/presence.d.ts +0 -20
- package/package.json +1 -1
- package/dist/components/Ddoc.svelte +0 -131
|
@@ -45,92 +45,64 @@
|
|
|
45
45
|
} = $props();
|
|
46
46
|
|
|
47
47
|
// Get Firestore instance only in browser environment
|
|
48
|
-
let firestore
|
|
49
|
-
let collectionRef: CollectionReference | Query | null = $state(null);
|
|
50
|
-
let collectionService: ReturnType<typeof firekitCollection> | null = $state(null);
|
|
48
|
+
let firestore = $derived(browser ? firebaseService.getDbInstance() : null);
|
|
51
49
|
|
|
52
|
-
//
|
|
53
|
-
let
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
// Create collection reference if path string is provided
|
|
51
|
+
let collectionRef = $derived(
|
|
52
|
+
firestore && typeof ref === 'string'
|
|
53
|
+
? collection(firestore, ref)
|
|
54
|
+
: (ref as CollectionReference | Query)
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// Create collection service with derived path
|
|
58
|
+
let collectionPath = $derived(typeof ref === 'string' ? ref : (ref as CollectionReference).path);
|
|
59
|
+
let collectionService = $state<ReturnType<typeof firekitCollection> | null>(null);
|
|
60
|
+
|
|
61
|
+
// Track collection state using derived computations
|
|
62
|
+
let collectionState = $derived({
|
|
63
|
+
loading: !browser
|
|
64
|
+
? false
|
|
65
|
+
: !firestore
|
|
66
|
+
? false
|
|
67
|
+
: !collectionService
|
|
68
|
+
? true
|
|
69
|
+
: collectionService.loading,
|
|
70
|
+
data: !browser
|
|
71
|
+
? (startWith ?? [])
|
|
72
|
+
: !firestore
|
|
73
|
+
? []
|
|
74
|
+
: !collectionService
|
|
75
|
+
? (startWith ?? [])
|
|
76
|
+
: collectionService.data,
|
|
77
|
+
error: !browser
|
|
78
|
+
? null
|
|
79
|
+
: !firestore
|
|
80
|
+
? new Error('Firestore instance not available')
|
|
81
|
+
: !collectionService
|
|
82
|
+
? null
|
|
83
|
+
: collectionService.error,
|
|
84
|
+
count: !browser
|
|
85
|
+
? (startWith?.length ?? 0)
|
|
86
|
+
: !firestore
|
|
87
|
+
? 0
|
|
88
|
+
: !collectionService
|
|
89
|
+
? (startWith?.length ?? 0)
|
|
90
|
+
: collectionService.size
|
|
58
91
|
});
|
|
59
92
|
|
|
60
|
-
//
|
|
93
|
+
// Set up collection service
|
|
61
94
|
$effect(() => {
|
|
62
|
-
if (!browser) {
|
|
63
|
-
|
|
64
|
-
loading: false,
|
|
65
|
-
data: startWith ?? [],
|
|
66
|
-
error: null,
|
|
67
|
-
count: startWith?.length ?? 0
|
|
68
|
-
};
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Initialize Firestore and collection service
|
|
73
|
-
firestore = firebaseService.getDbInstance();
|
|
74
|
-
if (!firestore) {
|
|
75
|
-
collectionState = {
|
|
76
|
-
loading: false,
|
|
77
|
-
data: [],
|
|
78
|
-
error: new Error('Firestore instance not available'),
|
|
79
|
-
count: 0
|
|
80
|
-
};
|
|
95
|
+
if (!browser || !collectionPath) {
|
|
96
|
+
collectionService = null;
|
|
81
97
|
return;
|
|
82
98
|
}
|
|
83
99
|
|
|
84
|
-
// Create
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// Create collection service
|
|
89
|
-
collectionService = firekitCollection(
|
|
90
|
-
typeof ref === 'string' ? ref : (ref as CollectionReference).path,
|
|
91
|
-
queryConstraints
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
// Update state based on collection service state
|
|
95
|
-
collectionState = {
|
|
96
|
-
loading: collectionService.loading,
|
|
97
|
-
data: collectionService.data,
|
|
98
|
-
error: collectionService.error,
|
|
99
|
-
count: collectionService.size
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// Set up event listener for real-time updates
|
|
103
|
-
const unsubscribe = collectionService.addEventListener((event) => {
|
|
104
|
-
if (event.type === 'data_changed') {
|
|
105
|
-
collectionState = {
|
|
106
|
-
loading: false,
|
|
107
|
-
data: event.data || [],
|
|
108
|
-
error: null,
|
|
109
|
-
count: event.data?.length || 0
|
|
110
|
-
};
|
|
111
|
-
} else if (event.type === 'error') {
|
|
112
|
-
collectionState = {
|
|
113
|
-
loading: false,
|
|
114
|
-
data: [],
|
|
115
|
-
error: event.error || null,
|
|
116
|
-
count: 0
|
|
117
|
-
};
|
|
118
|
-
} else if (event.type === 'loading_started') {
|
|
119
|
-
collectionState = {
|
|
120
|
-
...collectionState,
|
|
121
|
-
loading: true
|
|
122
|
-
};
|
|
123
|
-
} else if (event.type === 'loading_finished') {
|
|
124
|
-
collectionState = {
|
|
125
|
-
...collectionState,
|
|
126
|
-
loading: false
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
});
|
|
100
|
+
// Create new service when path or constraints change
|
|
101
|
+
const newService = firekitCollection(collectionPath, queryConstraints);
|
|
102
|
+
collectionService = newService;
|
|
130
103
|
|
|
131
104
|
return () => {
|
|
132
|
-
|
|
133
|
-
collectionService?.dispose();
|
|
105
|
+
newService?.dispose();
|
|
134
106
|
};
|
|
135
107
|
});
|
|
136
108
|
</script>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { firekitDoc } from '../services/document.svelte.js';
|
|
3
|
+
import { firebaseService } from '../firebase.js';
|
|
4
|
+
import { doc } from 'firebase/firestore';
|
|
5
|
+
import { browser } from '$app/environment';
|
|
6
|
+
import type { DocumentReference, DocumentData, Firestore } from 'firebase/firestore';
|
|
7
|
+
import type { Snippet } from 'svelte';
|
|
8
|
+
import type { DocumentOptions } from '../types/document.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Props for Doc component
|
|
12
|
+
*/
|
|
13
|
+
let {
|
|
14
|
+
ref,
|
|
15
|
+
startWith,
|
|
16
|
+
children,
|
|
17
|
+
loading,
|
|
18
|
+
options = {}
|
|
19
|
+
}: {
|
|
20
|
+
/**
|
|
21
|
+
* Firestore document reference or path string
|
|
22
|
+
*/
|
|
23
|
+
ref: DocumentReference | string;
|
|
24
|
+
/**
|
|
25
|
+
* Initial value to use before document is fetched
|
|
26
|
+
*/
|
|
27
|
+
startWith?: DocumentData | null;
|
|
28
|
+
/**
|
|
29
|
+
* Content to render when document is loaded
|
|
30
|
+
*/
|
|
31
|
+
children: Snippet<[DocumentData | null, DocumentReference, Firestore]>;
|
|
32
|
+
/**
|
|
33
|
+
* Content to render while loading
|
|
34
|
+
*/
|
|
35
|
+
loading?: Snippet<[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Document options for configuration
|
|
38
|
+
*/
|
|
39
|
+
options?: DocumentOptions;
|
|
40
|
+
} = $props();
|
|
41
|
+
|
|
42
|
+
// Get Firestore instance only in browser environment
|
|
43
|
+
let firestore = $derived(browser ? firebaseService.getDbInstance() : null);
|
|
44
|
+
|
|
45
|
+
// Create document reference if path string is provided
|
|
46
|
+
let docRef = $derived(
|
|
47
|
+
firestore && typeof ref === 'string' ? doc(firestore, ref) : (ref as DocumentReference)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// Create document service with derived path
|
|
51
|
+
let documentPath = $derived(typeof ref === 'string' ? ref : (ref as DocumentReference).path);
|
|
52
|
+
let documentService = $state<ReturnType<typeof firekitDoc> | null>(null);
|
|
53
|
+
|
|
54
|
+
// Track document state using derived computations
|
|
55
|
+
let documentState = $derived({
|
|
56
|
+
loading: !browser
|
|
57
|
+
? false
|
|
58
|
+
: !firestore
|
|
59
|
+
? false
|
|
60
|
+
: !documentService
|
|
61
|
+
? true
|
|
62
|
+
: documentService.loading,
|
|
63
|
+
data: !browser
|
|
64
|
+
? (startWith ?? null)
|
|
65
|
+
: !firestore
|
|
66
|
+
? null
|
|
67
|
+
: !documentService
|
|
68
|
+
? (startWith ?? null)
|
|
69
|
+
: documentService.data,
|
|
70
|
+
error: !browser
|
|
71
|
+
? null
|
|
72
|
+
: !firestore
|
|
73
|
+
? new Error('Firestore instance not available')
|
|
74
|
+
: !documentService
|
|
75
|
+
? null
|
|
76
|
+
: documentService.error,
|
|
77
|
+
canRefresh: !browser
|
|
78
|
+
? false
|
|
79
|
+
: !firestore
|
|
80
|
+
? false
|
|
81
|
+
: !documentService
|
|
82
|
+
? false
|
|
83
|
+
: documentService.canRefresh
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Set up document service and event listener
|
|
87
|
+
$effect(() => {
|
|
88
|
+
if (!browser || !documentPath) {
|
|
89
|
+
documentService = null;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Create new service when path or options change
|
|
94
|
+
const newService = firekitDoc(documentPath, startWith ?? undefined, options);
|
|
95
|
+
documentService = newService;
|
|
96
|
+
|
|
97
|
+
return () => {
|
|
98
|
+
newService?.dispose();
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
{#if !browser}
|
|
104
|
+
{@render children(startWith ?? null, null as any, null as any)}
|
|
105
|
+
{:else if !firestore}
|
|
106
|
+
<div class="flex items-center justify-center min-h-screen">
|
|
107
|
+
<div class="text-center">
|
|
108
|
+
<div class="text-red-500 text-lg font-semibold mb-2">Firestore Not Available</div>
|
|
109
|
+
<p class="text-gray-600">Firestore instance is not available.</p>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
{:else if documentState.loading}
|
|
113
|
+
{#if loading}
|
|
114
|
+
{@render loading()}
|
|
115
|
+
{:else}
|
|
116
|
+
<div class="flex items-center justify-center min-h-screen">
|
|
117
|
+
<div class="text-center">
|
|
118
|
+
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900 mx-auto"></div>
|
|
119
|
+
<p class="mt-2 text-gray-600">Loading document...</p>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
{/if}
|
|
123
|
+
{:else if documentState.error}
|
|
124
|
+
<div class="flex items-center justify-center min-h-screen">
|
|
125
|
+
<div class="text-center">
|
|
126
|
+
<div class="text-red-500 text-lg font-semibold mb-2">Error Loading Document</div>
|
|
127
|
+
<p class="text-gray-600 mb-4">{documentState.error.message}</p>
|
|
128
|
+
{#if documentState.canRefresh}
|
|
129
|
+
<button
|
|
130
|
+
class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
|
|
131
|
+
onclick={() => documentService?.refresh()}
|
|
132
|
+
>
|
|
133
|
+
Retry
|
|
134
|
+
</button>
|
|
135
|
+
{/if}
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
{:else}
|
|
139
|
+
{@render children(documentState.data, docRef!, firestore!)}
|
|
140
|
+
{/if}
|
|
@@ -23,6 +23,6 @@ type $$ComponentProps = {
|
|
|
23
23
|
*/
|
|
24
24
|
options?: DocumentOptions;
|
|
25
25
|
};
|
|
26
|
-
declare const
|
|
27
|
-
type
|
|
28
|
-
export default
|
|
26
|
+
declare const Doc: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
27
|
+
type Doc = ReturnType<typeof Doc>;
|
|
28
|
+
export default Doc;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { type UploadTaskSnapshot } from 'firebase/storage';
|
|
3
3
|
import { firebaseService } from '../firebase.js';
|
|
4
4
|
import { firekitUploadTask } from '../services/storage.svelte.js';
|
|
5
5
|
import { browser } from '$app/environment';
|
package/dist/firebase.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ declare class FirebaseService implements FirebaseServiceInstance {
|
|
|
18
18
|
functions: FirebaseServiceInstance['functions'];
|
|
19
19
|
database: FirebaseServiceInstance['database'];
|
|
20
20
|
storage: FirebaseServiceInstance['storage'];
|
|
21
|
+
analytics: FirebaseServiceInstance['analytics'];
|
|
21
22
|
status: FirebaseServiceStatus;
|
|
22
23
|
initializationError: Error | null;
|
|
23
24
|
readonly isBrowser: boolean;
|
|
@@ -93,6 +94,14 @@ declare class FirebaseService implements FirebaseServiceInstance {
|
|
|
93
94
|
* @throws {FirebaseServiceError} If Storage initialization fails
|
|
94
95
|
*/
|
|
95
96
|
getStorageInstance(): FirebaseServiceInstance['storage'];
|
|
97
|
+
/**
|
|
98
|
+
* Gets the Analytics instance, initializing it if necessary.
|
|
99
|
+
* Only available in browser environment.
|
|
100
|
+
*
|
|
101
|
+
* @returns {Analytics} The Analytics instance
|
|
102
|
+
* @throws {FirebaseServiceError} If Analytics initialization fails
|
|
103
|
+
*/
|
|
104
|
+
getAnalyticsInstance(): FirebaseServiceInstance['analytics'];
|
|
96
105
|
/**
|
|
97
106
|
* Resets the Firebase service to its initial state.
|
|
98
107
|
* Useful for testing or when you need to reinitialize the services.
|
package/dist/firebase.js
CHANGED
|
@@ -4,6 +4,7 @@ import { getAuth } from 'firebase/auth';
|
|
|
4
4
|
import { getFunctions } from 'firebase/functions';
|
|
5
5
|
import { getDatabase } from 'firebase/database';
|
|
6
6
|
import { getStorage } from 'firebase/storage';
|
|
7
|
+
import { getAnalytics } from 'firebase/analytics';
|
|
7
8
|
import { firebaseConfig } from './config.js';
|
|
8
9
|
import { FirebaseServiceStatus, FirebaseServiceError } from './types/firebase.js';
|
|
9
10
|
/**
|
|
@@ -25,6 +26,7 @@ class FirebaseService {
|
|
|
25
26
|
functions = null;
|
|
26
27
|
database = null;
|
|
27
28
|
storage = null;
|
|
29
|
+
analytics = null;
|
|
28
30
|
status = FirebaseServiceStatus.UNINITIALIZED;
|
|
29
31
|
initializationError = null;
|
|
30
32
|
isBrowser = typeof window !== 'undefined';
|
|
@@ -216,6 +218,27 @@ class FirebaseService {
|
|
|
216
218
|
throw new FirebaseServiceError('Failed to initialize Storage', 'storage');
|
|
217
219
|
}
|
|
218
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Gets the Analytics instance, initializing it if necessary.
|
|
223
|
+
* Only available in browser environment.
|
|
224
|
+
*
|
|
225
|
+
* @returns {Analytics} The Analytics instance
|
|
226
|
+
* @throws {FirebaseServiceError} If Analytics initialization fails
|
|
227
|
+
*/
|
|
228
|
+
getAnalyticsInstance() {
|
|
229
|
+
if (!this.isBrowser) {
|
|
230
|
+
throw new FirebaseServiceError('Analytics is not available in server environment', 'analytics');
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
if (!this.analytics) {
|
|
234
|
+
this.analytics = getAnalytics(this.getFirebaseApp());
|
|
235
|
+
}
|
|
236
|
+
return this.analytics;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
throw new FirebaseServiceError('Failed to initialize Analytics', 'analytics');
|
|
240
|
+
}
|
|
241
|
+
}
|
|
219
242
|
/**
|
|
220
243
|
* Resets the Firebase service to its initial state.
|
|
221
244
|
* Useful for testing or when you need to reinitialize the services.
|
|
@@ -229,6 +252,7 @@ class FirebaseService {
|
|
|
229
252
|
this.functions = null;
|
|
230
253
|
this.database = null;
|
|
231
254
|
this.storage = null;
|
|
255
|
+
this.analytics = null;
|
|
232
256
|
this.status = FirebaseServiceStatus.UNINITIALIZED;
|
|
233
257
|
this.initializationError = null;
|
|
234
258
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { firebaseService } from './firebase.js';
|
|
|
4
4
|
export { firekitUser } from './services/user.svelte.js';
|
|
5
5
|
export { firekitAuth } from './services/auth.js';
|
|
6
6
|
export { firekitPresence } from './services/presence.svelte.js';
|
|
7
|
+
export { firekitAnalytics } from './services/analytics.js';
|
|
7
8
|
export { firekitDoc, firekitDocOnce, firekitDocWithMetadata } from './services/document.svelte.js';
|
|
8
9
|
export { firekitDocMutations } from './services/mutations.js';
|
|
9
10
|
export { firekitCollection, firekitCollectionGroup, firekitCollectionOnce } from './services/collection.svelte.js';
|
|
@@ -14,7 +15,7 @@ export { default as AuthGuard } from './components/auth-guard.svelte';
|
|
|
14
15
|
export { default as CustomGuard } from './components/custom-guard.svelte';
|
|
15
16
|
export { default as SignedIn } from './components/signed-in.svelte';
|
|
16
17
|
export { default as SignedOut } from './components/signed-out.svelte';
|
|
17
|
-
export { default as Doc } from './components/
|
|
18
|
+
export { default as Doc } from './components/Doc.svelte';
|
|
18
19
|
export { default as Collection } from './components/Collection.svelte';
|
|
19
20
|
export { default as Node } from './components/Node.svelte';
|
|
20
21
|
export { default as NodeList } from './components/node-list.svelte';
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,8 @@ export { firebaseService } from './firebase.js';
|
|
|
7
7
|
export { firekitUser } from './services/user.svelte.js';
|
|
8
8
|
export { firekitAuth } from './services/auth.js';
|
|
9
9
|
export { firekitPresence } from './services/presence.svelte.js';
|
|
10
|
+
// analytics services
|
|
11
|
+
export { firekitAnalytics } from './services/analytics.js';
|
|
10
12
|
// document services
|
|
11
13
|
export { firekitDoc, firekitDocOnce, firekitDocWithMetadata } from './services/document.svelte.js';
|
|
12
14
|
// mutations services
|
|
@@ -23,7 +25,7 @@ export { default as AuthGuard } from './components/auth-guard.svelte';
|
|
|
23
25
|
export { default as CustomGuard } from './components/custom-guard.svelte';
|
|
24
26
|
export { default as SignedIn } from './components/signed-in.svelte';
|
|
25
27
|
export { default as SignedOut } from './components/signed-out.svelte';
|
|
26
|
-
export { default as Doc } from './components/
|
|
28
|
+
export { default as Doc } from './components/Doc.svelte';
|
|
27
29
|
export { default as Collection } from './components/Collection.svelte';
|
|
28
30
|
export { default as Node } from './components/Node.svelte';
|
|
29
31
|
export { default as NodeList } from './components/node-list.svelte';
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview FirekitAnalytics - Google Analytics Service for SvelteKit with Firebase Analytics
|
|
3
|
+
* @module FirekitAnalytics
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { type Analytics } from 'firebase/analytics';
|
|
7
|
+
import type { AnalyticsEvent, EcommerceItem, PurchaseEvent, FormSubmissionEvent, SearchEvent, PageViewEvent, EngagementEvent } from '../types/analytics.js';
|
|
8
|
+
/**
|
|
9
|
+
* Comprehensive Firebase Analytics service for SvelteKit applications.
|
|
10
|
+
* Provides a complete analytics solution with automatic user tracking,
|
|
11
|
+
* e-commerce tracking, and SvelteKit-specific features.
|
|
12
|
+
*
|
|
13
|
+
* @class FirekitAnalytics
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { firekitAnalytics } from 'svelte-firekit';
|
|
17
|
+
*
|
|
18
|
+
* // Track a custom event
|
|
19
|
+
* firekitAnalytics.trackEvent('button_click', { button_name: 'signup' });
|
|
20
|
+
*
|
|
21
|
+
* // Track a purchase
|
|
22
|
+
* firekitAnalytics.trackPurchase({
|
|
23
|
+
* transaction_id: 'T12345',
|
|
24
|
+
* value: 29.99,
|
|
25
|
+
* currency: 'USD',
|
|
26
|
+
* items: [{ item_id: 'prod_123', item_name: 'Premium Plan' }]
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare class FirekitAnalytics {
|
|
31
|
+
private static instance;
|
|
32
|
+
private analytics;
|
|
33
|
+
private _initialized;
|
|
34
|
+
private customParameters;
|
|
35
|
+
private debugMode;
|
|
36
|
+
private constructor();
|
|
37
|
+
/**
|
|
38
|
+
* Gets singleton instance of FirekitAnalytics
|
|
39
|
+
* @returns {FirekitAnalytics} The FirekitAnalytics instance
|
|
40
|
+
*/
|
|
41
|
+
static getInstance(): FirekitAnalytics;
|
|
42
|
+
/**
|
|
43
|
+
* Initializes the analytics service
|
|
44
|
+
*/
|
|
45
|
+
private initialize;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if analytics is available
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
private isAnalyticsAvailable;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the analytics instance
|
|
53
|
+
* @returns {Analytics | null} Firebase Analytics instance
|
|
54
|
+
*/
|
|
55
|
+
getAnalyticsInstance(): Analytics | null;
|
|
56
|
+
/**
|
|
57
|
+
* Checks if analytics is initialized
|
|
58
|
+
* @returns {boolean} True if analytics is initialized
|
|
59
|
+
*/
|
|
60
|
+
isInitialized(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Logs a custom analytics event
|
|
63
|
+
* @param {string} eventName Name of the event
|
|
64
|
+
* @param {Record<string, any>} parameters Event parameters
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* firekitAnalytics.trackEvent('button_click', {
|
|
69
|
+
* button_name: 'signup',
|
|
70
|
+
* page_location: '/home'
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
trackEvent(eventName: string, parameters?: Record<string, any>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Tracks page view events
|
|
77
|
+
* @param {PageViewEvent} pageView Page view data
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* firekitAnalytics.trackPageView({
|
|
82
|
+
* page_path: '/products',
|
|
83
|
+
* page_title: 'Products Page'
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
trackPageView(pageView: PageViewEvent): void;
|
|
88
|
+
/**
|
|
89
|
+
* Sets user ID for analytics
|
|
90
|
+
* @param {string | null} userId User ID or null to clear
|
|
91
|
+
*/
|
|
92
|
+
setUserId(userId: string | null): void;
|
|
93
|
+
/**
|
|
94
|
+
* Sets user properties for analytics
|
|
95
|
+
* @param {Record<string, any>} properties User properties
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* firekitAnalytics.setUserProperties({
|
|
100
|
+
* user_type: 'premium',
|
|
101
|
+
* subscription_plan: 'pro'
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
setUserProperties(properties: Record<string, any>): void;
|
|
106
|
+
/**
|
|
107
|
+
* Tracks purchase events
|
|
108
|
+
* @param {PurchaseEvent} purchase Purchase data
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* firekitAnalytics.trackPurchase({
|
|
113
|
+
* transaction_id: 'T12345',
|
|
114
|
+
* value: 29.99,
|
|
115
|
+
* currency: 'USD',
|
|
116
|
+
* items: [{
|
|
117
|
+
* item_id: 'prod_123',
|
|
118
|
+
* item_name: 'Premium Plan',
|
|
119
|
+
* price: 29.99
|
|
120
|
+
* }]
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
trackPurchase(purchase: PurchaseEvent): void;
|
|
125
|
+
/**
|
|
126
|
+
* Tracks add to cart events
|
|
127
|
+
* @param {EcommerceItem} item Item being added to cart
|
|
128
|
+
* @param {number} value Total value of the cart
|
|
129
|
+
* @param {string} currency Currency code
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* firekitAnalytics.trackAddToCart({
|
|
134
|
+
* item_id: 'prod_123',
|
|
135
|
+
* item_name: 'Premium Plan',
|
|
136
|
+
* price: 29.99
|
|
137
|
+
* }, 29.99, 'USD');
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
trackAddToCart(item: EcommerceItem, value: number, currency?: string): void;
|
|
141
|
+
/**
|
|
142
|
+
* Tracks remove from cart events
|
|
143
|
+
* @param {EcommerceItem} item Item being removed from cart
|
|
144
|
+
* @param {number} value Total value of the cart
|
|
145
|
+
* @param {string} currency Currency code
|
|
146
|
+
*/
|
|
147
|
+
trackRemoveFromCart(item: EcommerceItem, value: number, currency?: string): void;
|
|
148
|
+
/**
|
|
149
|
+
* Tracks view item events
|
|
150
|
+
* @param {EcommerceItem} item Item being viewed
|
|
151
|
+
*/
|
|
152
|
+
trackViewItem(item: EcommerceItem): void;
|
|
153
|
+
/**
|
|
154
|
+
* Tracks begin checkout events
|
|
155
|
+
* @param {EcommerceItem[]} items Items in cart
|
|
156
|
+
* @param {number} value Total value
|
|
157
|
+
* @param {string} currency Currency code
|
|
158
|
+
*/
|
|
159
|
+
trackBeginCheckout(items: EcommerceItem[], value: number, currency?: string): void;
|
|
160
|
+
/**
|
|
161
|
+
* Tracks form submission events
|
|
162
|
+
* @param {FormSubmissionEvent} formSubmission Form submission data
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* firekitAnalytics.trackFormSubmission({
|
|
167
|
+
* form_name: 'contact_form',
|
|
168
|
+
* success: true
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
trackFormSubmission(formSubmission: FormSubmissionEvent): void;
|
|
173
|
+
/**
|
|
174
|
+
* Tracks search events
|
|
175
|
+
* @param {SearchEvent} search Search data
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* firekitAnalytics.trackSearch({
|
|
180
|
+
* search_term: 'premium features',
|
|
181
|
+
* results_count: 15
|
|
182
|
+
* });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
trackSearch(search: SearchEvent): void;
|
|
186
|
+
/**
|
|
187
|
+
* Tracks custom conversion events
|
|
188
|
+
* @param {string} conversionName Name of the conversion
|
|
189
|
+
* @param {number} value Conversion value
|
|
190
|
+
* @param {string} currency Currency code
|
|
191
|
+
*/
|
|
192
|
+
trackConversion(conversionName: string, value?: number, currency?: string): void;
|
|
193
|
+
/**
|
|
194
|
+
* Tracks user engagement events
|
|
195
|
+
* @param {EngagementEvent} engagement Engagement data
|
|
196
|
+
*/
|
|
197
|
+
trackEngagement(engagement: EngagementEvent): void;
|
|
198
|
+
/**
|
|
199
|
+
* Initializes automatic page tracking for SvelteKit
|
|
200
|
+
* @param {boolean} trackInitialPage Whether to track the initial page load
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* // In your app.html or layout
|
|
205
|
+
* firekitAnalytics.initPageTracking();
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
initPageTracking(trackInitialPage?: boolean): void;
|
|
209
|
+
/**
|
|
210
|
+
* Tracks route changes manually (useful for custom routing)
|
|
211
|
+
* @param {string} route Route path
|
|
212
|
+
* @param {string} title Page title
|
|
213
|
+
*/
|
|
214
|
+
trackRouteChange(route: string, title?: string): void;
|
|
215
|
+
/**
|
|
216
|
+
* Sets custom parameters that will be included in all subsequent events
|
|
217
|
+
* @param {Record<string, any>} parameters Custom parameters
|
|
218
|
+
*/
|
|
219
|
+
setCustomParameters(parameters: Record<string, any>): void;
|
|
220
|
+
/**
|
|
221
|
+
* Clears custom parameters
|
|
222
|
+
*/
|
|
223
|
+
clearCustomParameters(): void;
|
|
224
|
+
/**
|
|
225
|
+
* Tracks multiple events in batch
|
|
226
|
+
* @param {AnalyticsEvent[]} events Array of events to track
|
|
227
|
+
*/
|
|
228
|
+
trackEvents(events: AnalyticsEvent[]): void;
|
|
229
|
+
/**
|
|
230
|
+
* Enables or disables analytics collection
|
|
231
|
+
* @param {boolean} enabled Whether to enable analytics collection
|
|
232
|
+
*/
|
|
233
|
+
setAnalyticsEnabled(enabled: boolean): void;
|
|
234
|
+
/**
|
|
235
|
+
* Sets debug mode for analytics
|
|
236
|
+
* @param {boolean} enabled Whether to enable debug mode
|
|
237
|
+
*/
|
|
238
|
+
setDebugMode(enabled: boolean): void;
|
|
239
|
+
/**
|
|
240
|
+
* Gets current debug mode status
|
|
241
|
+
* @returns {boolean} Current debug mode status
|
|
242
|
+
*/
|
|
243
|
+
getDebugMode(): boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Cleans up analytics resources
|
|
246
|
+
*/
|
|
247
|
+
cleanup(): void;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Pre-initialized singleton instance of FirekitAnalytics.
|
|
251
|
+
* This is the main export that should be used throughout your application.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* import { firekitAnalytics } from 'svelte-firekit';
|
|
256
|
+
*
|
|
257
|
+
* // Track a custom event
|
|
258
|
+
* firekitAnalytics.trackEvent('button_click', { button_name: 'signup' });
|
|
259
|
+
*
|
|
260
|
+
* // Initialize page tracking
|
|
261
|
+
* firekitAnalytics.initPageTracking();
|
|
262
|
+
*
|
|
263
|
+
* // Track a purchase
|
|
264
|
+
* firekitAnalytics.trackPurchase({
|
|
265
|
+
* transaction_id: 'T12345',
|
|
266
|
+
* value: 29.99,
|
|
267
|
+
* currency: 'USD'
|
|
268
|
+
* });
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
export declare const firekitAnalytics: FirekitAnalytics;
|
|
272
|
+
export {};
|