Amplitude not logging events

#1

Hey guys,

Segment keeps crashing on Android so this morning I decided to take a look at Amplitude.

I’ve wired up the initialization in my app.js here:

class App extends Component {
  state = {
    appIsReady: false,
    loggedIn: null,
  };

  componentWillMount() {
  
    // Comment this out when in production
    Amplitude.initialize(amplitudeAPIKeyDev);

    this._loadAssetsAsync();
  }

  async _loadAssetsAsync() {
    try {
      await cacheAssetsAsync({
        images,
        fonts,
      });
    } catch (e) {
      console.warn(
        'There was an error caching assets (see: main.js), perhaps due to a ' +
          'network timeout, so we skipped caching. Reload the app to try again.'
      );
      console.log(e.message);
    } finally {
      firebase.auth().onAuthStateChanged(user => {
        if (user) {
          const { currentUser } = firebase.auth();
   
          Amplitude.setUserId(currentUser.uid);

          this.setState({ loggedIn: true, appIsReady: true });
        } else this.setState({ loggedIn: false, appIsReady: true });
      });
    }
  }

  render() {

and then I’ve written up a redux middleware to log all my events to Amplitude:

const eventTracking = ({ getState }) => next => action => {
  const { type, payload } = action;

  if (actionsToTrack.hasOwnProperty(type.toUpperCase())) {
    switch (type) {
      case VOTE:
        trackVote(payload);
        break;
      case USER_ADDED_TO_DB:
        trackSignup(payload);
        break;
      case LOGIN_USER_SUCCESS:
        trackSignin(payload);
        break;
      case POST_COMMENT:
        trackPostComment(payload);
        break;
      case CREATE_POST:
        trackCreatePost(payload);
        break;
      case UNI_ONLY_TOGGLE:
        trackFilterFeedByUni(payload);
        break;
      case CHANGE_TOPIC_FILTER:
        trackFilterFeedByTopic(payload);
        break;
      case PROFILE_EDIT_SAVED:
        trackProfileEdited(payload);
        break;
      default:
        Amplitude.logEvent(type);
    }
  }

  return next(action);
};

const trackVote = payload => {
  const { voteToggle, user, postId } = payload;

  if (voteToggle)
    Amplitude.logEventWithProperties('Voted Post', {
      user,
      postId,
    });
};

const trackSignup = payload => {
  const { email, firstName, university, createdAt, firebaseUID } = payload;
  Amplitude.setUserId(firebaseUID);
  Amplitude.setUserProperties(firebaseUID, {
    createdAt,
    email,
    firstName,
    university,
  });

  Amplitude.logEventWithProperties('User Signed Up', {
    user: firebaseUID,
    createdAt,
    email,
    firstName,
    university,
  });
};

const trackSignin = payload => {
  const { firebaseUID } = payload;
  Amplitude.setUserId(firebaseUID);
  Amplitude.logEventWithProperties('User Signed In', {
    user: firebaseUID,
  });
};

const trackPostComment = payload => {
  const { postId, createdAt, id } = payload.comment;
  console.log(payload);
  Amplitude.logEventWithProperties('Commented On Post', {
    createdAt,
    postId,
    commentId: id,
  });
};

const trackCreatePost = payload => {
  const { university, createdAt, id, categories } = payload;
  console.log(payload);
  Amplitude.logEventWithProperties('Created Post', {
    createdAt,
    university,
    postId: id,
    categories,
  });
};

const trackFilterFeedByTopic = payload => {
  console.log(payload);
  Amplitude.logEventWithProperties('Filtered Feed By Topic', {
    topic: payload,
  });
};

const trackFilterFeedByUni = payload => {
  const toggle = payload;

  if (toggle) {
    console.log('Filtered feed by uni');
    Amplitude.logEvent('Filtered Feed By Uni');
  }
};

const trackProfileEdited = payload => {
  const { firebaseUID, firstName } = payload;
  console.log('First Name Changed');
  Amplitude.logEventWithProperties('First Name Changed', {
    firstName,
  });
};

export default eventTracking;

Right now, I’m getting all these console logs just fine whenever I need them but in Amplitude I’m only getting a couple of the events tracked.

I get ‘First Name Change’ most times and occasionally I get a few of the default cases in the switch statement.

I’m not getting anything else.

What’s happening here?

Thank you

#2

I’ve also upgraded to @expo.20.1.3 as I thought expo.20 was the issue

#3

Which platform is this on? In order to avoid spending lots of user battery and data plan, Amplitude has a buffer for events on the device that it periodically flushes to their servers. On iOS it appears that it will store up to 30 events for up to 30 seconds before it will flush the buffer. I’m not sure what the default is on Android, but since their docs don’t specify it I think it’s safe to assume the default values are comparable to the iOS side.

What happens if you generate a lot of events? Or if you leave the app open with the phone screen on for a minute or two after the events occur?

Related, I created a feature request to expose more of the Amplitude SDK’s config options in our JS wrapper: https://expo.canny.io/feature-requests/p/expose-amplitude-sdk-configuration-to-js

#4

Thanks for replying so quickly.

I’m not sending a lot of events at all.

Creating posts, creating comments. voting on posts etc. Nothing is being done too rapidly.

I’m experiencing the exact same issue on both iOS and Android.

#5

I don’t seem to see any changes whether I generate a lot of events or if I leave the phone screen on.

#6

Interesting. How many events are you generating in testing?

#7

related to 20.0.0 vs 20.0.3 issue?

#8

I got the same issue. For logEvent function, it works as normal.
For logEventWithProperties, clearUserProperties, they didn’t work as I cannot see any event on the dashboard.
I am sure the function calling them is running.