← back to Beverlyhillsvideos App

app/_layout.tsx

39 lines

import { useEffect, useState } from 'react';
import { Stack } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import * as SplashScreen from 'expo-splash-screen';
import { requestTrackingPermissionsAsync } from 'expo-tracking-transparency';

SplashScreen.preventAutoHideAsync();

export default function RootLayout() {
  // Hold the tracking WebView (tabs) until App Tracking Transparency resolves,
  // so the ATT prompt is answered BEFORE any GA4/GTM/Facebook Pixel/AdSense
  // request can fire (Guideline 5.1.2 — cross-site tracking requires ATT).
  const [attResolved, setAttResolved] = useState(false);

  useEffect(() => {
    (async () => {
      try {
        await requestTrackingPermissionsAsync();
      } catch {
        // proceed regardless — ATT is best-effort, never blocks the app
      } finally {
        setAttResolved(true);
        SplashScreen.hideAsync();
      }
    })();
  }, []);

  if (!attResolved) return null;

  return (
    <>
      <StatusBar style="dark" />
      <Stack screenOptions={{ headerShown: false }}>
        <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
      </Stack>
    </>
  );
}