Skip to content

Commit

Permalink
fix android Facebook analytics event
Browse files Browse the repository at this point in the history
  • Loading branch information
irov committed Jul 25, 2023
1 parent 4eb2058 commit 2b0fb54
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.Mengine.Plugin.Facebook;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
Expand Down Expand Up @@ -32,14 +33,15 @@
import org.Mengine.Base.MengineEvent;
import org.Mengine.Base.MenginePlugin;
import org.Mengine.Base.MenginePluginAnalyticsListener;
import org.Mengine.Base.MenginePluginApplicationListener;
import org.Mengine.Base.MenginePluginInvalidInitializeException;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;
import java.util.Map;

public class MengineFacebookPlugin extends MenginePlugin implements MenginePluginAnalyticsListener {
public class MengineFacebookPlugin extends MenginePlugin implements MenginePluginAnalyticsListener, MenginePluginApplicationListener {
public static final String PLUGIN_NAME = "Facebook";
public static final boolean PLUGIN_EMBEDDING = true;

Expand All @@ -59,9 +61,26 @@ public void onEvent(MengineApplication application, MengineEvent event, Object .
}
}

@Override
public void onAppPrepare(MengineApplication application) throws MenginePluginInvalidInitializeException {
Context context = application.getApplicationContext();

m_logger = AppEventsLogger.newLogger(context);
}

@Override
public void onAppCreate(MengineApplication application) throws MenginePluginInvalidInitializeException {
//Empty
}

@Override
public void onAppTerminate(MengineApplication application) {
m_logger = null;
}

@Override
public void onCreate(MengineActivity activity, Bundle savedInstanceState) throws MenginePluginInvalidInitializeException {
if (BuildConfig.DEBUG) {
if (BuildConfig.DEBUG == true) {
FacebookSdk.setIsDebugEnabled(true);
FacebookSdk.addLoggingBehavior(LoggingBehavior.APP_EVENTS);
}
Expand Down Expand Up @@ -187,13 +206,11 @@ public void onError(@NonNull FacebookException e) {
MengineApplication application = this.getMengineApplication();
AppEventsLogger.activateApp(application);
} catch (Exception ex) {
MengineFacebookPlugin.this.logError("activateApp catch exception: %s"
this.logError("activateApp catch exception: %s"
, ex.getLocalizedMessage()
);
}

m_logger = AppEventsLogger.newLogger(activity);

AccessToken accessToken = AccessToken.getCurrentAccessToken();
if (accessToken != null) {
m_facebookUserId = accessToken.getUserId();
Expand All @@ -219,6 +236,10 @@ public void onActivityResult(MengineActivity activity, int requestCode, int resu

@Override
public void onMengineAnalyticsEvent(MengineApplication application, int eventType, String eventName, long timestamp, Map<String, Object> context, Map<String, Object> parameters) {
if (m_logger == null) {
return;
}

switch (eventType) {
case EAET_CUSTOM: {
Bundle params = new Bundle();
Expand Down Expand Up @@ -284,6 +305,27 @@ public void onMengineAnalyticsEvent(MengineApplication application, int eventTyp

m_logger.logEvent(AppEventsConstants.EVENT_NAME_UNLOCKED_ACHIEVEMENT, params);
} break;
case EAET_LEVEL_UP: {
//ToDo EAET_LEVEL_UP
}break;
case EAET_LEVEL_START: {
//ToDo EAET_LEVEL_START
}break;
case EAET_LEVEL_END: {
//ToDo EAET_LEVEL_END
}break;
case EAET_SELECT_ITEM: {
//ToDo EAET_SELECT_ITEM
}break;
case EAET_TUTORIAL_BEGIN: {
//ToDo EAET_TUTORIAL_BEGIN
}break;
case EAET_TUTORIAL_COMPLETE: {
//ToDo EAET_TUTORIAL_COMPLETE
}break;
case EAET_SCREEN_VIEW: {
//ToDo EAET_SCREEN_VIEW
}break;
default: {
this.logError("unknown event type: %d name: %s"
, eventType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void onAppCreate(MengineApplication application) throws MenginePluginInva
//Empty
}

@Override
public void onAppTerminate(MengineApplication application) {
m_firebaseAnalytics = null;
}

@Override
public void onMengineAnalyticsEvent(MengineApplication application, int eventType, String eventName, long timestamp, Map<String, Object> context, Map<String, Object> parameters) {
switch (eventType) {
Expand Down

0 comments on commit 2b0fb54

Please sign in to comment.