-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathFirebaseAnalysis.ts
68 lines (60 loc) · 1.97 KB
/
FirebaseAnalysis.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { setDoc, doc, serverTimestamp, getDoc } from 'firebase/firestore';
import { User } from 'firebase/auth';
import { firebase, userColsRef } from './firebase';
import { useEffect } from 'react';
import { UserDocType } from './firebase_doctypes';
export async function addLoggedInUser(user: User) {
if (!user) return;
const userDoc = doc(userColsRef, user.email as string);
const userData: UserDocType = {
email: user.email,
emailVerified: user.emailVerified,
displayName: user.displayName,
isAnonymous: user.isAnonymous,
phoneNumber: user.phoneNumber,
photoURL: user.photoURL,
providerId: user.providerId,
uid: user.uid,
comment: '',
createdAt: serverTimestamp(),
isPublic: true,
repo: 0
};
try {
const docSnapShot = await getDoc(userDoc);
if(!docSnapShot.exists()) setDoc(userDoc, userData, { merge: true });
} catch(_) {
setDoc(userDoc, userData, { merge: true });
}
}
export enum FIREBASE_ANALYTICS_EVENTS {
// pages
home_page = 'home_page',
profile = 'profile',
time_table = 'time_table',
free_classrooms = 'free_classrooms',
developer = 'developer',
contribute = 'contribute',
notifications = 'notifications',
clash_resolver = 'clash_resolver',
// click events
updated_timetable = 'updated_timetable',
link_share_on_whatsapp = 'link_share_on_whatsapp',
print_time_table = 'print_time_table',
promotion_closed = 'promotion_closed',
teacher_timetable = 'teacher_timetable',
room_activities = 'room_activities',
// affiliate
educative = 'educative',
freeForAdvertisement = 'free_for_advertisement',
}
import { logEvent } from 'firebase/analytics';
export function reportFirebaseAnalytics(key: string, val: any) {
if (!firebase.firebaseAnalytics) return;
logEvent(firebase.firebaseAnalytics, key, val);
}
export function useFirebaseAnalyticsReport(eventName: FIREBASE_ANALYTICS_EVENTS) {
useEffect(() => {
reportFirebaseAnalytics(eventName.toString(), {});
}, [eventName]);
}