I am trying to log custom events in the Android app using Facebook analytics. The custom events are working correctly whenever I log them in MainActivity and other Activities in my app, but are not getting logged at all when I log them inside Fragments and static methods.
I initialize the Facebook SDK and AppEventsLogger in my Application class like his:
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
And I track events in my app like this:
TrackingService.logEvent(getActivity(), "Public.Clicked");
And here is the logEvent method that I defined in my TrackingService:
static public void logEvent(Activity activity, String event) {
AppEventsLogger logger = AppEventsLogger.newLogger(activity);
logger.logEvent(event);
}
When I call logEvent in a method in my MainActivity, the event shows up in my Facebook Analytics dashboard:
TrackingService.logEvent(MainActivity.this, "SearchTestA");
When I call logEvent in a method in one of my Fragments that is contained within MainActivity, the event does not show up in my dashboard:
TrackingService.logEvent(getActivity(), "Public.Clicked");
I have confirmed that getActivity() above returns an instance of MainActivity. Any idea what I'm doing wrong?
Turns out you can't have periods in your event names. Underscores and spaces are allowed, though.