Firebase analytics
Skill DentVega/firebase-agent-skills/skills/firebase-analytics
Community Firebase agent skills for AI coding assistants — Expo / React Native focus
npx -y skills add DentVega/firebase-agent-skills --skill firebase-analyticsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Sets up Firebase Analytics (Google Analytics for Firebase) on web and Expo / React Native — installing, logging custom events, setting user properties, debugging in real time, integrating with BigQuery for raw events, and respecting iOS ATT consent. Use whenever the user wants to track product usage, funnels, or user demographics.
SKILL.md
6.2 KB, as published. Nobody here has run it
Firebase Analytics
Minimum viable example
import analytics from "@react-native-firebase/analytics";
await analytics().logEvent("post_created", { category: "blog", word_count: 450 });
await analytics().setUserProperty("tier", "pro");
Event names: lowercase_snake_case, ≤ 40 chars, ≤ 25 params per event. Violations are silently dropped — verify with DebugView before shipping.
1. Install
Web
npm install firebase
import { getAnalytics, isSupported } from "firebase/analytics";
let analytics: ReturnType<typeof getAnalytics> | null = null;
isSupported().then((ok) => {
if (ok) analytics = getAnalytics(app);
});
isSupported() is required for SSR (Next.js) — getAnalytics throws in non-browser environments.
Expo / React Native
npx expo install @react-native-firebase/analytics
Add to app.json:
{
"expo": {
"plugins": ["@react-native-firebase/app", "@react-native-firebase/analytics"]
}
}
Rebuild (npx expo prebuild --clean + EAS Build).
2. iOS App Tracking Transparency (ATT)
For any IDFA-based analytics (cross-app tracking, ad attribution), iOS 14.5+ requires explicit user consent via the ATT prompt. Without it, IDFA is zeroed out and ad measurement breaks.
npx expo install expo-tracking-transparency
app.json:
{
"expo": {
"ios": {
"infoPlist": {
"NSUserTrackingUsageDescription": "We use this to measure ad performance and personalize content."
}
}
}
}
import { requestTrackingPermissionsAsync } from "expo-tracking-transparency";
const { status } = await requestTrackingPermissionsAsync();
// status is "granted" | "denied" | "restricted" | "undetermined"
Firebase Analytics still works without ATT for first-party events and aggregate metrics — only IDFA-linked features (Audiences for ads, attribution) are affected.
If shipping in the EEA, UK, or Switzerland, you also need Google Consent Mode v2 — see references/consent-mode.md. Without it, Google blocks all data from those regions.
3. Log events
import analytics from "@react-native-firebase/analytics";
await analytics().logEvent("post_created", {
category: "blog",
word_count: 450,
});
Reserved events (screen_view, login, sign_up, purchase, search, etc.) get richer reporting — use them when applicable:
await analytics().logLogin({ method: "google" });
await analytics().logSignUp({ method: "email" });
await analytics().logPurchase({
currency: "USD",
value: 9.99,
items: [{ item_id: "pro_monthly", item_name: "Pro Monthly", price: 9.99 }],
});
Event naming rules
- Lowercase snake_case
- ≤ 40 characters
- ≤ 25 parameters per event
- Parameter names ≤ 40 chars, values ≤ 100 chars (string) or
number
Events that violate these rules are silently dropped. Test in DebugView (next section).
4. Real-time debugging (DebugView)
The Analytics dashboard has a 24h delay. For development, use DebugView for real-time event verification:
# iOS Simulator
xcrun simctl spawn booted log stream --predicate 'subsystem == "com.google.firebase.analytics"'
# Or enable persistently:
adb shell setprop debug.firebase.analytics.app <your.package.name>
For iOS, in Xcode → Edit Scheme → Run → Arguments → add -FIRDebugEnabled to "Arguments Passed On Launch".
Open Firebase Console → Analytics → DebugView → your device appears, events stream in seconds.
5. User properties and IDs
await analytics().setUserId(user.uid);
await analytics().setUserProperty("tier", "pro");
await analytics().setUserProperty("signup_source", "google");
User properties are usable as Audiences for Remote Config targeting and Firebase Messaging campaigns. They're also dimensions in BigQuery exports.
Privacy: never set personally identifiable strings as user properties (email, name, phone). Use anonymous IDs only. The userId accepts an opaque string — your Firebase Auth uid is fine.
6. Screen tracking (React Navigation)
import analytics from "@react-native-firebase/analytics";
import { useRef } from "react";
import { NavigationContainer } from "@react-navigation/native";
const navigationRef = useRef<NavigationContainerRef<any>>(null);
const routeNameRef = useRef<string>();
<NavigationContainer
ref={navigationRef}
onReady={() => { routeNameRef.current = navigationRef.current?.getCurrentRoute()?.name; }}
onStateChange={async () => {
const previous = routeNameRef.current;
const current = navigationRef.current?.getCurrentRoute()?.name;
if (previous !== current) {
await analytics().logScreenView({ screen_name: current, screen_class: current });
}
routeNameRef.current = current;
}}
>
For Expo Router, hook into the useSegments() change instead.
7. BigQuery export
For raw event analysis beyond what the console offers, enable BigQuery export:
Firebase Console → Project Settings → Integrations → BigQuery → Link.
Events stream to a daily-partitioned table (events_YYYYMMDD) with ~1 hour delay. Pricing: free under 1M events/day; standard BigQuery beyond.
8. Common mistakes
- Calling
getAnalyticsin Next.js withoutisSupported. Throws during SSR. - Expecting events in the dashboard immediately. 24h delay. Use DebugView for verification.
- Naming events in CamelCase or with spaces. Silently rejected.
- Setting PII as user properties. Violates Google's terms and risks account suspension.
- Forgetting to rebuild after adding the plugin.
@react-native-firebase/analyticsrequires native code. - Treating Analytics as a real-time event bus. It's batched. For real-time, write events to Firestore or Pub/Sub.