Esempio n. 1
1
  private static void ActivateApp(String appId) {
    if (!activateAppCalled.compareAndSet(false, true)) {
      Log.w(TAG, "Activite app only needs to be called once");
      return;
    }
    final Activity unityActivity = getUnityActivity();
    if (appId != null) {
      AppEventsLogger.activateApp(unityActivity.getApplication(), appId);
    } else {
      AppEventsLogger.activateApp(unityActivity.getApplication());
    }

    // We already have a running activity so we need to call create activity to ensure the
    // logging is correct
    new Handler(Looper.getMainLooper())
        .post(
            new Runnable() {
              @Override
              public void run() {
                // These calls should be run on the ui thread.
                ActivityLifecycleTracker.onActivityCreated(unityActivity);
                ActivityLifecycleTracker.onActivityResumed(unityActivity);
              }
            });
  }
  private void executeLogEvent(JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    if (args.length() == 0) {
      // Not enough parameters
      callbackContext.error("Invalid arguments");
      return;
    }

    String eventName = args.getString(0);
    if (args.length() == 1) {
      logger.logEvent(eventName);
      callbackContext.success();
      return;
    }

    // Arguments is greater than 1
    JSONObject params = args.getJSONObject(1);
    Bundle parameters = new Bundle();
    Iterator<String> iter = params.keys();

    while (iter.hasNext()) {
      String key = iter.next();
      try {
        // Try get a String
        String value = params.getString(key);
        parameters.putString(key, value);
      } catch (JSONException e) {
        // Maybe it was an int
        Log.w(TAG, "Type in AppEvent parameters was not String for key: " + key);
        try {
          int value = params.getInt(key);
          parameters.putInt(key, value);
        } catch (JSONException e2) {
          // Nope
          Log.e(TAG, "Unsupported type in AppEvent parameters for key: " + key);
        }
      }
    }

    if (args.length() == 2) {
      logger.logEvent(eventName, parameters);
      callbackContext.success();
    }

    if (args.length() == 3) {
      double value = args.getDouble(2);
      logger.logEvent(eventName, value, parameters);
      callbackContext.success();
    }
  }
  public void logAuthorizationMethodComplete(
      String authId,
      String method,
      String result,
      String errorMessage,
      String errorCode,
      Map<String, String> loggingExtras) {

    Bundle bundle;
    bundle = LoginLogger.newAuthorizationLoggingBundle(authId);
    if (result != null) {
      bundle.putString(LoginLogger.EVENT_PARAM_LOGIN_RESULT, result);
    }
    if (errorMessage != null) {
      bundle.putString(LoginLogger.EVENT_PARAM_ERROR_MESSAGE, errorMessage);
    }
    if (errorCode != null) {
      bundle.putString(LoginLogger.EVENT_PARAM_ERROR_CODE, errorCode);
    }
    if (loggingExtras != null && !loggingExtras.isEmpty()) {
      JSONObject jsonObject = new JSONObject(loggingExtras);
      bundle.putString(LoginLogger.EVENT_PARAM_EXTRAS, jsonObject.toString());
    }
    bundle.putString(EVENT_PARAM_METHOD, method);

    appEventsLogger.logSdkEvent(EVENT_NAME_LOGIN_METHOD_COMPLETE, null, bundle);
  }
 @Override
 public void onResume(boolean multitasking) {
   super.onResume(multitasking);
   // Developers can observe how frequently users activate their app by logging an app activation
   // event.
   AppEventsLogger.activateApp(cordova.getActivity());
 }
Esempio n. 5
0
  @Override
  protected void onPause() {
    super.onPause();

    // Logs 'app deactivate' App Event.
    AppEventsLogger.deactivateApp(this);
  }
Esempio n. 6
0
  @Override
  protected void onResume() {
    super.onResume();

    // Logs 'install' and 'app activate' App Events.
    AppEventsLogger.activateApp(this);
  }
Esempio n. 7
0
 @Override
 protected void onResume() {
   super.onResume();
   Profile profile = Profile.getCurrentProfile();
   displayWelcomeMessage(profile);
   AppEventsLogger.activateApp(this);
 }
  public void logUnexpectedError(String eventName, String errorMessage, String method) {
    Bundle bundle = newAuthorizationLoggingBundle("");
    bundle.putString(EVENT_PARAM_LOGIN_RESULT, LoginClient.Result.Code.ERROR.getLoggingValue());
    bundle.putString(EVENT_PARAM_ERROR_MESSAGE, errorMessage);
    bundle.putString(EVENT_PARAM_METHOD, method);

    appEventsLogger.logSdkEvent(eventName, null, bundle);
  }
Esempio n. 9
0
  @Override
  protected void onResume() {
    super.onResume();
    // Get source of open for app re-engagement
    mobileAppTracker.setReferralSources(this);
    // MAT will not function unless the measureSession call is included
    mobileAppTracker.measureSession();

    String facebookId = ManifestMetadataUtils.getString(this, "com.facebook.sdk.ApplicationId");
    AppEventsLogger.activateApp(this, facebookId);
    Log.xd(this, facebookId);
  }
Esempio n. 10
0
  public void logStartLogin(LoginClient.Request pendingLoginRequest) {
    Bundle bundle = newAuthorizationLoggingBundle(pendingLoginRequest.getAuthId());

    // Log what we already know about the call in start event
    try {
      JSONObject extras = new JSONObject();
      extras.put(EVENT_EXTRAS_LOGIN_BEHAVIOR, pendingLoginRequest.getLoginBehavior().toString());
      extras.put(EVENT_EXTRAS_REQUEST_CODE, LoginClient.getLoginRequestCode());
      extras.put(
          EVENT_EXTRAS_PERMISSIONS, TextUtils.join(",", pendingLoginRequest.getPermissions()));
      extras.put(
          EVENT_EXTRAS_DEFAULT_AUDIENCE, pendingLoginRequest.getDefaultAudience().toString());
      extras.put(EVENT_EXTRAS_IS_REAUTHORIZE, pendingLoginRequest.isRerequest());
      bundle.putString(EVENT_PARAM_EXTRAS, extras.toString());
    } catch (JSONException e) {
    }

    appEventsLogger.logSdkEvent(EVENT_NAME_LOGIN_START, null, bundle);
  }
Esempio n. 11
0
  public void logCompleteLogin(
      String loginRequestId,
      Map<String, String> loggingExtras,
      LoginClient.Result.Code result,
      Map<String, String> resultExtras,
      Exception exception) {

    Bundle bundle = newAuthorizationLoggingBundle(loginRequestId);
    if (result != null) {
      bundle.putString(EVENT_PARAM_LOGIN_RESULT, result.getLoggingValue());
    }
    if (exception != null && exception.getMessage() != null) {
      bundle.putString(EVENT_PARAM_ERROR_MESSAGE, exception.getMessage());
    }

    // Combine extras from the request and from the result.
    JSONObject jsonObject = null;
    if (loggingExtras.isEmpty() == false) {
      jsonObject = new JSONObject(loggingExtras);
    }
    if (resultExtras != null) {
      if (jsonObject == null) {
        jsonObject = new JSONObject();
      }
      try {
        for (Map.Entry<String, String> entry : resultExtras.entrySet()) {
          jsonObject.put(entry.getKey(), entry.getValue());
        }
      } catch (JSONException e) {
      }
    }
    if (jsonObject != null) {
      bundle.putString(EVENT_PARAM_EXTRAS, jsonObject.toString());
    }

    appEventsLogger.logSdkEvent(EVENT_NAME_LOGIN_COMPLETE, null, bundle);
  }
 @Override
 protected void onPause() {
   super.onPause();
   AppEventsLogger.deactivateApp(this);
 }
 @Override
 protected void onResume() {
   super.onResume();
   AppEventsLogger.activateApp(this);
 }
Esempio n. 14
0
    @Override
    public void onClick(View v) {
      callExternalOnClickListener(v);

      Context context = getContext();

      AccessToken accessToken = AccessToken.getCurrentAccessToken();

      if (accessToken != null) {
        // Log out
        if (confirmLogout) {
          // Create a confirmation dialog
          String logout = getResources().getString(R.string.com_facebook_loginview_log_out_action);
          String cancel = getResources().getString(R.string.com_facebook_loginview_cancel_action);
          String message;
          Profile profile = Profile.getCurrentProfile();
          if (profile != null && profile.getName() != null) {
            message =
                String.format(
                    getResources().getString(R.string.com_facebook_loginview_logged_in_as),
                    profile.getName());
          } else {
            message =
                getResources().getString(R.string.com_facebook_loginview_logged_in_using_facebook);
          }
          AlertDialog.Builder builder = new AlertDialog.Builder(context);
          builder
              .setMessage(message)
              .setCancelable(true)
              .setPositiveButton(
                  logout,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      getLoginManager().logOut();
                    }
                  })
              .setNegativeButton(cancel, null);
          builder.create().show();
        } else {
          getLoginManager().logOut();
        }
      } else {
        LoginManager loginManager = getLoginManager();
        loginManager.setDefaultAudience(getDefaultAudience());
        loginManager.setLoginBehavior(getLoginBehavior());

        if (LoginAuthorizationType.PUBLISH.equals(properties.authorizationType)) {
          if (LoginButton.this.getFragment() != null) {
            loginManager.logInWithPublishPermissions(
                LoginButton.this.getFragment(), properties.permissions);
          } else {
            loginManager.logInWithPublishPermissions(
                LoginButton.this.getActivity(), properties.permissions);
          }
        } else {
          if (LoginButton.this.getFragment() != null) {
            loginManager.logInWithReadPermissions(
                LoginButton.this.getFragment(), properties.permissions);
          } else {
            loginManager.logInWithReadPermissions(
                LoginButton.this.getActivity(), properties.permissions);
          }
        }
      }

      AppEventsLogger logger = AppEventsLogger.newLogger(getContext());

      Bundle parameters = new Bundle();
      parameters.putInt("logging_in", (accessToken != null) ? 0 : 1);

      logger.logSdkEvent(loginLogoutEventName, null, parameters);
    }
Esempio n. 15
0
 private static AppEventsLogger getAppEventsLogger() {
   if (appEventsLogger == null) {
     appEventsLogger = AppEventsLogger.newLogger(getUnityActivity().getApplicationContext());
   }
   return appEventsLogger;
 }
  @Override
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
      throws JSONException {
    if (action.equals("login")) {
      executeLogin(args, callbackContext);
      return true;

    } else if (action.equals("logout")) {
      if (hasAccessToken()) {
        LoginManager.getInstance().logOut();
        callbackContext.success();
      } else {
        callbackContext.error("No valid session found, must call init and login before logout.");
      }
      return true;

    } else if (action.equals("getLoginStatus")) {
      callbackContext.success(getResponse());
      return true;

    } else if (action.equals("getAccessToken")) {
      if (hasAccessToken()) {
        callbackContext.success(AccessToken.getCurrentAccessToken().getToken());
      } else {
        // Session not open
        callbackContext.error("Session not open.");
      }
      return true;

    } else if (action.equals("logEvent")) {
      executeLogEvent(args, callbackContext);
      return true;

    } else if (action.equals("logPurchase")) {
      /*
       * While calls to logEvent can be made to register purchase events,
       * there is a helper method that explicitly takes a currency indicator.
       */
      if (args.length() != 2) {
        callbackContext.error("Invalid arguments");
        return true;
      }
      int value = args.getInt(0);
      String currency = args.getString(1);
      logger.logPurchase(BigDecimal.valueOf(value), Currency.getInstance(currency));
      callbackContext.success();
      return true;

    } else if (action.equals("showDialog")) {
      executeDialog(args, callbackContext);
      return true;

    } else if (action.equals("graphApi")) {
      executeGraph(args, callbackContext);

      return true;
    } else if (action.equals("appInvite")) {
      executeAppInvite(args, callbackContext);

      return true;
    }
    return false;
  }
Esempio n. 17
0
  LoginLogger(Context context, String applicationId) {
    this.applicationId = applicationId;

    appEventsLogger = AppEventsLogger.newLogger(context, applicationId);
  }
 @Override
 public void onPause(boolean multitasking) {
   super.onPause(multitasking);
   AppEventsLogger.deactivateApp(cordova.getActivity());
 }
Esempio n. 19
0
  public void logAuthorizationMethodStart(String authId, String method) {
    Bundle bundle = LoginLogger.newAuthorizationLoggingBundle(authId);
    bundle.putString(EVENT_PARAM_METHOD, method);

    appEventsLogger.logSdkEvent(EVENT_NAME_LOGIN_METHOD_START, null, bundle);
  }
  @Override
  protected void pluginInitialize() {
    FacebookSdk.sdkInitialize(cordova.getActivity().getApplicationContext());

    // create callbackManager
    callbackManager = CallbackManager.Factory.create();

    // create AppEventsLogger
    logger = AppEventsLogger.newLogger(cordova.getActivity().getApplicationContext());

    // Set up the activity result callback to this class
    cordova.setActivityResultCallback(this);

    LoginManager.getInstance()
        .registerCallback(
            callbackManager,
            new FacebookCallback<LoginResult>() {
              @Override
              public void onSuccess(final LoginResult loginResult) {
                GraphRequest.newMeRequest(
                        loginResult.getAccessToken(),
                        new GraphRequest.GraphJSONObjectCallback() {
                          @Override
                          public void onCompleted(JSONObject jsonObject, GraphResponse response) {
                            if (response.getError() != null) {
                              if (graphContext != null) {
                                graphContext.error(
                                    getFacebookRequestErrorResponse(response.getError()));
                              } else if (loginContext != null) {
                                loginContext.error(
                                    getFacebookRequestErrorResponse(response.getError()));
                              }
                              return;
                            }

                            // If this login comes after doing a new permission request
                            // make the outstanding graph call
                            if (graphContext != null) {
                              makeGraphCall();
                              return;
                            }

                            Log.d(TAG, "returning login object " + jsonObject.toString());
                            loginContext.success(getResponse());
                            loginContext = null;
                          }
                        })
                    .executeAsync();
              }

              @Override
              public void onCancel() {
                FacebookOperationCanceledException e = new FacebookOperationCanceledException();
                handleError(e, loginContext);
              }

              @Override
              public void onError(FacebookException e) {
                Log.e("Activity", String.format("Error: %s", e.toString()));
                handleError(e, loginContext);
              }
            });

    shareDialog = new ShareDialog(cordova.getActivity());
    shareDialog.registerCallback(
        callbackManager,
        new FacebookCallback<Sharer.Result>() {
          @Override
          public void onSuccess(Sharer.Result result) {
            if (showDialogContext != null) {
              showDialogContext.success(result.getPostId());
              showDialogContext = null;
            }
          }

          @Override
          public void onCancel() {
            FacebookOperationCanceledException e = new FacebookOperationCanceledException();
            handleError(e, showDialogContext);
          }

          @Override
          public void onError(FacebookException e) {
            Log.e("Activity", String.format("Error: %s", e.toString()));
            handleError(e, showDialogContext);
          }
        });

    messageDialog = new MessageDialog(cordova.getActivity());
    messageDialog.registerCallback(
        callbackManager,
        new FacebookCallback<Sharer.Result>() {
          @Override
          public void onSuccess(Sharer.Result result) {
            if (showDialogContext != null) {
              showDialogContext.success();
              showDialogContext = null;
            }
          }

          @Override
          public void onCancel() {
            FacebookOperationCanceledException e = new FacebookOperationCanceledException();
            handleError(e, showDialogContext);
          }

          @Override
          public void onError(FacebookException e) {
            Log.e("Activity", String.format("Error: %s", e.toString()));
            handleError(e, showDialogContext);
          }
        });

    gameRequestDialog = new GameRequestDialog(cordova.getActivity());
    gameRequestDialog.registerCallback(
        callbackManager,
        new FacebookCallback<GameRequestDialog.Result>() {
          @Override
          public void onSuccess(GameRequestDialog.Result result) {
            if (showDialogContext != null) {
              try {
                JSONObject json = new JSONObject();
                json.put("requestId", result.getRequestId());
                json.put("recipientsIds", new JSONArray(result.getRequestRecipients()));
                showDialogContext.success();
                showDialogContext = null;
              } catch (JSONException ex) {
                showDialogContext.success();
                showDialogContext = null;
              }
            }
          }

          @Override
          public void onCancel() {
            FacebookOperationCanceledException e = new FacebookOperationCanceledException();
            handleError(e, showDialogContext);
          }

          @Override
          public void onError(FacebookException e) {
            Log.e("Activity", String.format("Error: %s", e.toString()));
            handleError(e, showDialogContext);
          }
        });

    appInviteDialog = new AppInviteDialog(cordova.getActivity());
    appInviteDialog.registerCallback(
        callbackManager,
        new FacebookCallback<AppInviteDialog.Result>() {
          @Override
          public void onSuccess(AppInviteDialog.Result result) {
            if (showDialogContext != null) {
              showDialogContext.success();
              showDialogContext = null;
            }
          }

          @Override
          public void onCancel() {
            FacebookOperationCanceledException e = new FacebookOperationCanceledException();
            handleError(e, showDialogContext);
          }

          @Override
          public void onError(FacebookException e) {
            Log.e("Activity", String.format("Error: %s", e.toString()));
            handleError(e, showDialogContext);
          }
        });
  }