analytics().logEvent does not seem to be working on Android

Expected Behavior

This code should log an event “myEvent”:

import RNFirebase from 'react-native-firebase';

const firebaseApp = RNFirebase.initializeApp({ debug: false });
firebaseApp.analytics().logEvent("myEvent");

Actual Behavior

I don’t see “myEvent” anywhere in my Firebase dashboard analytics. Other, default Firebase events, such as “app_open”, “session_start” are all being recorded, and I believe that’s happening from react-native-firebase.

Build:

  • RN: 0.45.0
  • RN-Firebase: 1.1.0
  • Emulator: Nexus 5X API 25

Praise

This library is so much nicer than using the WebSDK, thank you for all your work.

Author: Fantashit

4 thoughts on “analytics().logEvent does not seem to be working on Android

  1. Thanks @dannycochran, very kind of you to say!

    Firebase analytics events can sometimes take a little while to come through on the dashboard. You can however turn on debug view which should allow you to debug in realtime by following the instructions here: https://firebase.google.com/docs/analytics/debugview

    Let me know if you’re still having problems once you’ve tried debug mode and I can take another look. Events are definitely working in my iOS and Android app at the moment…

  2. Yeah that’s normal. They can take hours annoyingly! Same with Performance Monitoring, takes yonks.

  3. @dannycochran for reference, what I’ve found is that when you first sending events it takes a while to come through then they generally come through a bit quicker after that. Still nowhere near realtime though!!

  4. Maybe this is useful in the future. I use analytics like so (this is typescript)

    I’m using current-as-of-now versions of everything (react-native 0.60.5, react-native-firebase v5.5.6, iOS Firebase SDK Pods 6.7.0, Android Firebase SDK BOM 2.20.0

    contents of ./src/utilities/Analytics.ts

    import * as firebase from 'react-native-firebase';
    
    /**
     * Easily log an analytics event. Guaranteed to succeed.
     * Will sanity check arguments for correctness vs underlying analytics provider,
     * and log errors (possibly via analytics if possible)
     *
     * @param name 40 character max alphanumeric and '_' only, starts with alpha
     * @param props keys 40 character max w/name content rules, values 100 character max
     */
    function analyticsEvent(name: string, props?: Object | undefined): void {
      try {
        firebase.analytics().logEvent(name, props);
      } catch (e) {
        console.log('Unable to tag analytics event:', e);
      }
    }
    
    /**
     * Set user properties
     * @param props keys 24 char max alphanumeric and '_' only starts alpha, values 26 char max
     */
    function setAnalyticsUserProperties(props: { [key: string]: string | null }): void {
      firebase.analytics().setUserProperties(props);
    }
    
    function setAnalyticsUser(id: string): void {
      firebase.analytics().setUserId(id);
    }
    
    function analyticsScreen(screenName: string): void {
      firebase.analytics().setCurrentScreen(screenName, screenName);
    }
    
    /**
     * Verify that we follow google rules for analytics string contents
     * If there is a problem it will have the side-effect of logging a reportable event
     * for followup to fix the problem
     * @param value string to verify
     * @param maxLength optional max length of the string, defaults to 40
     */
    function checkAnalyticsString(value: string, maxLength: number = 40): boolean {
      let badEvent = 'errorInvalidAnalyticsEvent';
      if (value.length > maxLength) {
        firebase.analytics().logEvent(badEvent, { badKey: value.substr(0, maxLength - 1) });
        return false;
      }
    
      if (!/^[a-zA-Z][_a-zA-Z0-9]+$/.test(value)) {
        firebase.analytics().logEvent(badEvent, { badKey: value });
        return false;
      }
    
      return true;
    }
    
    export {
      analyticsEvent,
      setAnalyticsUserProperties,
      setAnalyticsUser,
      analyticsScreen,
      checkAnalyticsString,
    };

    Usage:

    import { analyticsEvent } from '../utilities/Analytics';
    
    ...
    // inside some function somewhere
                analyticsEvent('updateDelayed');
    // inside some other function
        analyticsEvent('onEnterPhoneNumber', { phoneNumber: phoneNumber });

    It works for me ?

Comments are closed.

analytics().logEvent does not seem to be working on Android

Expected Behavior

This code should log an event “myEvent”:

import RNFirebase from 'react-native-firebase';

const firebaseApp = RNFirebase.initializeApp({ debug: false });
firebaseApp.analytics().logEvent("myEvent");

Actual Behavior

I don’t see “myEvent” anywhere in my Firebase dashboard analytics. Other, default Firebase events, such as “app_open”, “session_start” are all being recorded, and I believe that’s happening from react-native-firebase.

Build:

  • RN: 0.45.0
  • RN-Firebase: 1.1.0
  • Emulator: Nexus 5X API 25

Praise

This library is so much nicer than using the WebSDK, thank you for all your work.

Author: Fantashit

3 thoughts on “analytics().logEvent does not seem to be working on Android

  1. Thanks @dannycochran, very kind of you to say!

    Firebase analytics events can sometimes take a little while to come through on the dashboard. You can however turn on debug view which should allow you to debug in realtime by following the instructions here: https://firebase.google.com/docs/analytics/debugview

    Let me know if you’re still having problems once you’ve tried debug mode and I can take another look. Events are definitely working in my iOS and Android app at the moment…

  2. Maybe this is useful in the future. I use analytics like so (this is typescript)

    I’m using current-as-of-now versions of everything (react-native 0.60.5, react-native-firebase v5.5.6, iOS Firebase SDK Pods 6.7.0, Android Firebase SDK BOM 2.20.0

    contents of ./src/utilities/Analytics.ts

    import * as firebase from 'react-native-firebase';
    
    /**
     * Easily log an analytics event. Guaranteed to succeed.
     * Will sanity check arguments for correctness vs underlying analytics provider,
     * and log errors (possibly via analytics if possible)
     *
     * @param name 40 character max alphanumeric and '_' only, starts with alpha
     * @param props keys 40 character max w/name content rules, values 100 character max
     */
    function analyticsEvent(name: string, props?: Object | undefined): void {
      try {
        firebase.analytics().logEvent(name, props);
      } catch (e) {
        console.log('Unable to tag analytics event:', e);
      }
    }
    
    /**
     * Set user properties
     * @param props keys 24 char max alphanumeric and '_' only starts alpha, values 26 char max
     */
    function setAnalyticsUserProperties(props: { [key: string]: string | null }): void {
      firebase.analytics().setUserProperties(props);
    }
    
    function setAnalyticsUser(id: string): void {
      firebase.analytics().setUserId(id);
    }
    
    function analyticsScreen(screenName: string): void {
      firebase.analytics().setCurrentScreen(screenName, screenName);
    }
    
    /**
     * Verify that we follow google rules for analytics string contents
     * If there is a problem it will have the side-effect of logging a reportable event
     * for followup to fix the problem
     * @param value string to verify
     * @param maxLength optional max length of the string, defaults to 40
     */
    function checkAnalyticsString(value: string, maxLength: number = 40): boolean {
      let badEvent = 'errorInvalidAnalyticsEvent';
      if (value.length > maxLength) {
        firebase.analytics().logEvent(badEvent, { badKey: value.substr(0, maxLength - 1) });
        return false;
      }
    
      if (!/^[a-zA-Z][_a-zA-Z0-9]+$/.test(value)) {
        firebase.analytics().logEvent(badEvent, { badKey: value });
        return false;
      }
    
      return true;
    }
    
    export {
      analyticsEvent,
      setAnalyticsUserProperties,
      setAnalyticsUser,
      analyticsScreen,
      checkAnalyticsString,
    };

    Usage:

    import { analyticsEvent } from '../utilities/Analytics';
    
    ...
    // inside some function somewhere
                analyticsEvent('updateDelayed');
    // inside some other function
        analyticsEvent('onEnterPhoneNumber', { phoneNumber: phoneNumber });

    It works for me ?

  3. Pingback: DevSecOps

Comments are closed.