下面列出了怎么用com.facebook.AppEventsLogger的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
void logAppEvents(boolean doneButtonClicked) {
AppEventsLogger logger = AppEventsLogger.newLogger(this.getActivity(), getSession());
Bundle parameters = new Bundle();
// If Done was clicked, we know this completed successfully. If not, we don't know (caller might have
// dismissed us in response to selection changing, or user might have hit back button). Either way
// we'll log the number of selections.
String outcome = doneButtonClicked ? AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_COMPLETED :
AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_UNKNOWN;
parameters.putString(AnalyticsEvents.PARAMETER_DIALOG_OUTCOME, outcome);
parameters.putInt("num_friends_picked", getSelection().size());
logger.logSdkEvent(AnalyticsEvents.EVENT_FRIEND_PICKER_USAGE, null, parameters);
}
@Override
void logAppEvents(boolean doneButtonClicked) {
AppEventsLogger logger = AppEventsLogger.newLogger(this.getActivity(), getSession());
Bundle parameters = new Bundle();
// If Done was clicked, we know this completed successfully. If not, we don't know (caller might have
// dismissed us in response to selection changing, or user might have hit back button). Either way
// we'll log the number of selections.
String outcome = doneButtonClicked ? AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_COMPLETED :
AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_UNKNOWN;
parameters.putString(AnalyticsEvents.PARAMETER_DIALOG_OUTCOME, outcome);
parameters.putInt("num_friends_picked", getSelection().size());
logger.logSdkEvent(AnalyticsEvents.EVENT_FRIEND_PICKER_USAGE, null, parameters);
}
@Override
protected void onResume() {
super.onResume();
// Call the 'activateApp' method to log an app event for use in analytics and advertising
// reporting. Do so in
// the onResume methods of the primary Activities that an app may be launched into.
AppEventsLogger.activateApp(this);
if (DeviceInfo.INSTANCE.isNetworkConnected()) {
informReferralToServer();
}
}
@Override
void logAppEvents(boolean doneButtonClicked) {
AppEventsLogger logger = AppEventsLogger.newLogger(this.getActivity(), getSession());
Bundle parameters = new Bundle();
// If Done was clicked, we know this completed successfully. If not, we don't know (caller might have
// dismissed us in response to selection changing, or user might have hit back button). Either way
// we'll log the number of selections.
String outcome = doneButtonClicked ? AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_COMPLETED :
AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_UNKNOWN;
parameters.putString(AnalyticsEvents.PARAMETER_DIALOG_OUTCOME, outcome);
parameters.putInt("num_friends_picked", getSelection().size());
logger.logSdkEvent(AnalyticsEvents.EVENT_FRIEND_PICKER_USAGE, null, parameters);
}
@Override
void logAppEvents(boolean doneButtonClicked) {
AppEventsLogger logger = AppEventsLogger.newLogger(this.getActivity(), getSession());
Bundle parameters = new Bundle();
// If Done was clicked, we know this completed successfully. If not, we don't know (caller might have
// dismissed us in response to selection changing, or user might have hit back button). Either way
// we'll log the number of selections.
String outcome = doneButtonClicked ? AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_COMPLETED :
AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_UNKNOWN;
parameters.putString(AnalyticsEvents.PARAMETER_DIALOG_OUTCOME, outcome);
parameters.putInt("num_friends_picked", getSelection().size());
logger.logSdkEvent(AnalyticsEvents.EVENT_FRIEND_PICKER_USAGE, null, parameters);
}
@Override
void logAppEvents(boolean doneButtonClicked) {
AppEventsLogger logger = AppEventsLogger.newLogger(this.getActivity(), getSession());
Bundle parameters = new Bundle();
// If Done was clicked, we know this completed successfully. If not, we don't know (caller might have
// dismissed us in response to selection changing, or user might have hit back button). Either way
// we'll log the number of selections.
String outcome = doneButtonClicked ? AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_COMPLETED :
AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_UNKNOWN;
parameters.putString(AnalyticsEvents.PARAMETER_DIALOG_OUTCOME, outcome);
parameters.putInt("num_friends_picked", getSelection().size());
logger.logSdkEvent(AnalyticsEvents.EVENT_FRIEND_PICKER_USAGE, null, parameters);
}
@Override
void logAppEvents(boolean doneButtonClicked) {
AppEventsLogger logger = AppEventsLogger.newLogger(this.getActivity(), getSession());
Bundle parameters = new Bundle();
// If Done was clicked, we know this completed successfully. If not, we don't know (caller might have
// dismissed us in response to selection changing, or user might have hit back button). Either way
// we'll log the number of selections.
String outcome = doneButtonClicked ? AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_COMPLETED :
AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_UNKNOWN;
parameters.putString(AnalyticsEvents.PARAMETER_DIALOG_OUTCOME, outcome);
parameters.putInt("num_friends_picked", getSelection().size());
logger.logSdkEvent(AnalyticsEvents.EVENT_FRIEND_PICKER_USAGE, null, parameters);
}
@Override
void logAppEvents(boolean doneButtonClicked) {
AppEventsLogger logger = AppEventsLogger.newLogger(this.getActivity(), getSession());
Bundle parameters = new Bundle();
// If Done was clicked, we know this completed successfully. If not, we don't know (caller might have
// dismissed us in response to selection changing, or user might have hit back button). Either way
// we'll log the number of selections.
String outcome = doneButtonClicked ? AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_COMPLETED :
AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_UNKNOWN;
parameters.putString(AnalyticsEvents.PARAMETER_DIALOG_OUTCOME, outcome);
parameters.putInt("num_friends_picked", getSelection().size());
logger.logSdkEvent(AnalyticsEvents.EVENT_FRIEND_PICKER_USAGE, null, parameters);
}
@Override
void logAppEvents(boolean doneButtonClicked) {
AppEventsLogger logger = AppEventsLogger.newLogger(this.getActivity(), getSession());
Bundle parameters = new Bundle();
// If Done was clicked, we know this completed successfully. If not, we don't know (caller might have
// dismissed us in response to selection changing, or user might have hit back button). Either way
// we'll log the number of selections.
String outcome = doneButtonClicked ? AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_COMPLETED :
AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_UNKNOWN;
parameters.putString(AnalyticsEvents.PARAMETER_DIALOG_OUTCOME, outcome);
parameters.putInt("num_friends_picked", getSelection().size());
logger.logSdkEvent(AnalyticsEvents.EVENT_FRIEND_PICKER_USAGE, null, parameters);
}
@Override
public void onClick(View v) {
Context context = getContext();
final Session openSession = sessionTracker.getOpenSession();
if (openSession != null) {
// If the Session is currently open, it must mean we need to 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;
if (user != null && user.getName() != null) {
message = String.format(getResources().getString(R.string.com_facebook_loginview_logged_in_as), user.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) {
openSession.closeAndClearTokenInformation();
}
})
.setNegativeButton(cancel, null);
builder.create().show();
} else {
openSession.closeAndClearTokenInformation();
}
} else {
Session currentSession = sessionTracker.getSession();
if (currentSession == null || currentSession.getState().isClosed()) {
sessionTracker.setSession(null);
Session session = new Session.Builder(context).setApplicationId(applicationId).build();
Session.setActiveSession(session);
currentSession = session;
}
if (!currentSession.isOpened()) {
Session.OpenRequest openRequest = null;
if (parentFragment != null) {
openRequest = new Session.OpenRequest(parentFragment);
} else if (context instanceof Activity) {
openRequest = new Session.OpenRequest((Activity)context);
}
if (openRequest != null) {
openRequest.setDefaultAudience(properties.defaultAudience);
openRequest.setPermissions(properties.permissions);
openRequest.setLoginBehavior(properties.loginBehavior);
if (SessionAuthorizationType.PUBLISH.equals(properties.authorizationType)) {
currentSession.openForPublish(openRequest);
} else {
currentSession.openForRead(openRequest);
}
}
}
}
AppEventsLogger logger = AppEventsLogger.newLogger(getContext());
Bundle parameters = new Bundle();
parameters.putInt("logging_in", (openSession != null) ? 0 : 1);
logger.logSdkEvent(loginLogoutEventName, null, parameters);
}
@Override
public void onClick(View v) {
Context context = getContext();
final Session openSession = sessionTracker.getOpenSession();
if (openSession != null) {
// If the Session is currently open, it must mean we need to 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;
if (user != null && user.getName() != null) {
message = String.format(getResources().getString(R.string.com_facebook_loginview_logged_in_as), user.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) {
openSession.closeAndClearTokenInformation();
}
})
.setNegativeButton(cancel, null);
builder.create().show();
} else {
openSession.closeAndClearTokenInformation();
}
} else {
Session currentSession = sessionTracker.getSession();
if (currentSession == null || currentSession.getState().isClosed()) {
sessionTracker.setSession(null);
Session session = new Session.Builder(context).setApplicationId(applicationId).build();
Session.setActiveSession(session);
currentSession = session;
}
if (!currentSession.isOpened()) {
Session.OpenRequest openRequest = null;
if (parentFragment != null) {
openRequest = new Session.OpenRequest(parentFragment);
} else if (context instanceof Activity) {
openRequest = new Session.OpenRequest((Activity)context);
}
if (openRequest != null) {
openRequest.setDefaultAudience(properties.defaultAudience);
openRequest.setPermissions(properties.permissions);
openRequest.setLoginBehavior(properties.loginBehavior);
if (SessionAuthorizationType.PUBLISH.equals(properties.authorizationType)) {
currentSession.openForPublish(openRequest);
} else {
currentSession.openForRead(openRequest);
}
}
}
}
AppEventsLogger logger = AppEventsLogger.newLogger(getContext());
Bundle parameters = new Bundle();
parameters.putInt("logging_in", (openSession != null) ? 0 : 1);
logger.logSdkEvent(loginLogoutEventName, null, parameters);
}