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