Skip to content

Commit 2d4ac3e

Browse files
authored
cleanup
1 parent 30056ee commit 2d4ac3e

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

api/src/index.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,18 @@ export function addSessionIdListener(
5454
/** Creates a listener source for a streamer's private data with a pull key. */
5555
export function forPullKey(pullKey: string) {
5656
const db = getDatabase(getApp());
57+
const analytics = getAnalytics(getApp());
5758
const reference = child(ref(db, "pullables"), pullKey);
59+
const safeLogEvent = (eventName: string, eventParams?: any) => {
60+
isSupported()
61+
.then((supported) => {
62+
if (supported) {
63+
logEvent(analytics, eventName, eventParams);
64+
}
65+
})
66+
.catch(() => {});
67+
};
68+
5869
return {
5970
addLocationListener(callback: (location: Location) => void) {
6071
safeLogEvent("listener", { type: "location", pullKey });
@@ -188,23 +199,3 @@ function getApp() {
188199
}
189200
return app;
190201
}
191-
192-
const safeLogEvent = (() => {
193-
let analyticsInstance: Analytics | null = null;
194-
195-
return (eventName: string, eventParams?: any) => {
196-
if (analyticsInstance) {
197-
logEvent(analyticsInstance, eventName, eventParams);
198-
return;
199-
}
200-
201-
isSupported()
202-
.then((supported) => {
203-
if (supported) {
204-
analyticsInstance = getAnalytics(getApp());
205-
logEvent(analyticsInstance, eventName, eventParams);
206-
}
207-
})
208-
.catch(() => {});
209-
};
210-
})();

0 commit comments

Comments
 (0)