Created
November 20, 2025 11:54
-
-
Save erenkulaksiz/740a04c5d332540732ddbaf3a0604177 to your computer and use it in GitHub Desktop.
analytics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "./firebase"; | |
| import "./global.css"; | |
| import "react-native-gesture-handler"; | |
| import "expo-router/entry"; | |
| import initSentry from "@mobile/utils/sentry"; | |
| import { | |
| getInitialNotification, | |
| getMessaging, | |
| onNotificationOpenedApp, | |
| setBackgroundMessageHandler, | |
| } from "@react-native-firebase/messaging"; | |
| import * as SplashScreen from "expo-splash-screen"; | |
| import { cssInterop } from "nativewind"; | |
| import { Image } from "expo-image"; | |
| import { analytics } from "@mobile/events/manager"; | |
| import { | |
| AppsFlyerProvider, | |
| GoogleAnalyticsProvider, | |
| PostHogProvider, | |
| } from "@/events/providers"; | |
| import eventNames from "@/events/names"; | |
| import sendEvent from "@mobile/events/sendEvent"; | |
| import { I18nManager } from "react-native"; | |
| analytics.configure({ | |
| providers: [ | |
| new AppsFlyerProvider(), | |
| new GoogleAnalyticsProvider(), | |
| new PostHogProvider(), | |
| ], | |
| enabled: true, | |
| }); | |
| // ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export interface AnalyticsConfig { | |
| providers: AnalyticsProvider[]; | |
| enabled: boolean; | |
| } | |
| export interface AnalyticsProvider { | |
| name: string; | |
| track(event: string, properties: any): void; | |
| } | |
| export default class AnalyticsManager { | |
| private static instance: AnalyticsManager; | |
| private config: AnalyticsConfig = { providers: [], enabled: true }; | |
| private constructor() {} | |
| static getInstance(): AnalyticsManager { | |
| if (!AnalyticsManager.instance) { | |
| AnalyticsManager.instance = new AnalyticsManager(); | |
| } | |
| return AnalyticsManager.instance; | |
| } | |
| configure(config: AnalyticsConfig) { | |
| console.log( | |
| "[AnalyticsManager] configure", | |
| config.providers.map((p) => p.name) | |
| ); | |
| this.config = config; | |
| } | |
| track(event: string, properties: any = {}) { | |
| if (!this.config.enabled) return; | |
| console.log("[AnalyticsManager]", event, properties); | |
| this.config.providers.forEach((provider) => { | |
| try { | |
| provider.track(event, properties); | |
| } catch (error) { | |
| console.error("[AnalyticsManager] provider error:", error); | |
| } | |
| }); | |
| } | |
| } | |
| export const analytics = AnalyticsManager.getInstance(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { getAnalytics, logEvent } from "@react-native-firebase/analytics"; | |
| import AppsFlyer from "react-native-appsflyer"; | |
| import { AnalyticsProvider } from "@mobile/events/manager"; | |
| import { posthog } from "@mobile/events/posthog"; | |
| export class PostHogProvider implements AnalyticsProvider { | |
| name = "posthog"; | |
| track(event: string, properties: any) { | |
| posthog.capture(event, properties); | |
| } | |
| } | |
| export class GoogleAnalyticsProvider implements AnalyticsProvider { | |
| name = "google"; | |
| track(event: string, properties: any) { | |
| const analytics = getAnalytics(); | |
| logEvent(analytics, event, properties); | |
| } | |
| } | |
| export class AppsFlyerProvider implements AnalyticsProvider { | |
| name = "appsflyer"; | |
| track(event: string, properties: any) { | |
| AppsFlyer.logEvent(event, properties); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment