Java Code Examples for com.facebook.appevents.AppEventsLogger#newLogger()

The following examples show how to use com.facebook.appevents.AppEventsLogger#newLogger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginLogger.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
LoginLogger(Context context, String applicationId) {
    this.applicationId = applicationId;

    appEventsLogger = AppEventsLogger.newLogger(context, applicationId);

    // Store which version of facebook is installed
    try {
        PackageManager packageManager = context.getPackageManager();
        if (packageManager != null) {
            PackageInfo facebookInfo = packageManager.getPackageInfo(FACEBOOK_PACKAGE_NAME, 0);
            if (facebookInfo != null) {
                facebookVersion = facebookInfo.versionName;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        // Do nothing, just ignore and not log
    }
}
 
Example 2
Source File: FirstLaunchAnalytics.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
public Completable sendAppStart(android.app.Application application,
    SharedPreferences sharedPreferences, IdsRepository idsRepository) {

  FacebookSdk.sdkInitialize(application);
  AppEventsLogger.activateApp(application);
  AppEventsLogger.newLogger(application);
  return idsRepository.getUniqueIdentifier()
      .doOnSuccess(AppEventsLogger::setUserID)
      .toObservable()
      .doOnNext(__ -> setupRakamFirstLaunchSuperProperty(
          SecurePreferences.isFirstRun(sharedPreferences)))
      .doOnNext(__ -> sendPlayProtectEvent())
      .doOnNext(__ -> setupDimensions(application))
      .filter(__ -> SecurePreferences.isFirstRun(sharedPreferences))
      .doOnNext(
          __ -> sendFirstLaunchEvent(utmSource, utmMedium, utmCampaign, utmContent, entryPoint))
      .toCompletable()
      .subscribeOn(Schedulers.io());
}
 
Example 3
Source File: ShareInternalUtility.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private static void logShareResult(String shareOutcome, String errorMessage) {
    Context context = FacebookSdk.getApplicationContext();
    AppEventsLogger logger = AppEventsLogger.newLogger(context);
    Bundle parameters = new Bundle();
    parameters.putString(
            AnalyticsEvents.PARAMETER_SHARE_OUTCOME,
            shareOutcome
    );

    if (errorMessage != null) {
        parameters.putString(AnalyticsEvents.PARAMETER_SHARE_ERROR_MESSAGE, errorMessage);
    }
    logger.logSdkEvent(AnalyticsEvents.EVENT_SHARE_RESULT, null, parameters);
}
 
Example 4
Source File: LoginMethodHandler.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
protected void logWebLoginCompleted(String e2e) {
    String applicationId = loginClient.getPendingRequest().getApplicationId();
    AppEventsLogger appEventsLogger =
            AppEventsLogger.newLogger(loginClient.getActivity(), applicationId);

    Bundle parameters = new Bundle();
    parameters.putString(AnalyticsEvents.PARAMETER_WEB_LOGIN_E2E, e2e);
    parameters.putLong(
            AnalyticsEvents.PARAMETER_WEB_LOGIN_SWITCHBACK_TIME, System.currentTimeMillis());
    parameters.putString(AnalyticsEvents.PARAMETER_APP_ID, applicationId);

    appEventsLogger.logSdkEvent(AnalyticsEvents.EVENT_WEB_LOGIN_COMPLETE, null, parameters);
}
 
Example 5
Source File: DialogPresenter.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
public static void logDialogActivity(
        Context context,
        String eventName,
        String outcome) {
    AppEventsLogger logger = AppEventsLogger.newLogger(context);
    Bundle parameters = new Bundle();
    parameters.putString(AnalyticsEvents.PARAMETER_DIALOG_OUTCOME, outcome);
    logger.logSdkEvent(eventName, null, parameters);
}
 
Example 6
Source File: BoltsMeasurementEventListener.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    AppEventsLogger appEventsLogger = AppEventsLogger.newLogger(context);
    String eventName = BOLTS_MEASUREMENT_EVENT_PREFIX +
            intent.getStringExtra(MEASUREMENT_EVENT_NAME_KEY);
    Bundle eventArgs = intent.getBundleExtra(MEASUREMENT_EVENT_ARGS_KEY);
    Bundle logData = new Bundle();
    for(String key : eventArgs.keySet()) {
       String safeKey = key.replaceAll(
               "[^0-9a-zA-Z _-]", "-").replaceAll("^[ -]*", "").replaceAll("[ -]*$", "");
       logData.putString(safeKey, (String)eventArgs.get(key));
    }
    appEventsLogger.logEvent(eventName, logData);
}
 
Example 7
Source File: Analytics.java    From openshop.io-android with MIT License 5 votes vote down vote up
/**
 * Prepare Google analytics trackers and Facebook events logger.
 * Send UTM campaign if exist.
 *
 * @param shop    shop with app specific Google Ua or null, if global tracker is enough.
 * @param context application context.
 */
public static synchronized void prepareTrackersAndFbLogger(Shop shop, Context context) {
    GoogleAnalytics analytics = GoogleAnalytics.getInstance(context);
    // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG

    if (shop == null) {
        deleteAppTrackers();
    } else {
        if (!mTrackers.containsKey(TRACKER_APP) && analytics != null) {
            if (shop.getGoogleUa() != null && !shop.getGoogleUa().isEmpty()) {
                Timber.d("Set new app tracker with id: %s", shop.getGoogleUa());
                // App tracker determined by shop
                Tracker appTracker = analytics.newTracker(shop.getGoogleUa());
                appTracker.enableAutoActivityTracking(true);
                appTracker.enableExceptionReporting(false);
                appTracker.enableAdvertisingIdCollection(true);
                mTrackers.put(TRACKER_APP, appTracker);
            } else {
                Timber.e(new RuntimeException(), "Creating GA app tracker with empty Google UA");
            }
        } else {
            Timber.e("Trackers for this app already exist.");
        }
    }

    // Add global tracker only one time.
    if (!mTrackers.containsKey(TRACKER_GLOBAL) && analytics != null) {
        Timber.d("Set new global tracker.");
        // Global app tracker
        Tracker appTrackerGlobal = analytics.newTracker(R.xml.global_tracker);
        appTrackerGlobal.enableAutoActivityTracking(true);
        appTrackerGlobal.enableExceptionReporting(true);
        appTrackerGlobal.enableAdvertisingIdCollection(true);
        mTrackers.put(TRACKER_GLOBAL, appTrackerGlobal);
        // Send camping info only once time.
        sendCampaignInfo();
    }

    facebookLogger = AppEventsLogger.newLogger(MyApplication.getInstance());
}
 
Example 8
Source File: FacebookButtonBase.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
private void logButtonCreated(final Context context) {
    AppEventsLogger logger = AppEventsLogger.newLogger(context);
    logger.logSdkEvent(analyticsButtonCreatedEventName, null, null);
}
 
Example 9
Source File: FacebookButtonBase.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
private void logButtonTapped(final Context context) {
    AppEventsLogger logger = AppEventsLogger.newLogger(context);
    logger.logSdkEvent(analyticsButtonTappedEventName, null, null);
}
 
Example 10
Source File: LikeActionController.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
private AppEventsLogger getAppEventsLogger() {
    if (appEventsLogger == null) {
        appEventsLogger = AppEventsLogger.newLogger(FacebookSdk.getApplicationContext());
    }
    return appEventsLogger;
}
 
Example 11
Source File: ShareDialog.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
private void logDialogShare(Context context, ShareContent content, Mode mode) {
    String displayType;
    if (isAutomaticMode) {
        mode = Mode.AUTOMATIC;
    }

    switch (mode) {
        case AUTOMATIC:
            displayType = AnalyticsEvents.PARAMETER_SHARE_DIALOG_SHOW_AUTOMATIC;
            break;
        case WEB:
            displayType = AnalyticsEvents.PARAMETER_SHARE_DIALOG_SHOW_WEB;
            break;
        case NATIVE:
            displayType = AnalyticsEvents.PARAMETER_SHARE_DIALOG_SHOW_NATIVE;
            break;
        default:
            displayType = AnalyticsEvents.PARAMETER_SHARE_DIALOG_SHOW_UNKNOWN;
            break;
    }

    String contentType;
    DialogFeature dialogFeature = getFeature(content.getClass());
    if (dialogFeature == ShareDialogFeature.SHARE_DIALOG) {
        contentType = AnalyticsEvents.PARAMETER_SHARE_DIALOG_CONTENT_STATUS;
    } else if (dialogFeature == ShareDialogFeature.PHOTOS) {
        contentType = AnalyticsEvents.PARAMETER_SHARE_DIALOG_CONTENT_PHOTO;
    } else if (dialogFeature == ShareDialogFeature.VIDEO) {
        contentType = AnalyticsEvents.PARAMETER_SHARE_DIALOG_CONTENT_VIDEO;
    } else if (dialogFeature == OpenGraphActionDialogFeature.OG_ACTION_DIALOG) {
        contentType = AnalyticsEvents.PARAMETER_SHARE_DIALOG_CONTENT_OPENGRAPH;
    } else {
        contentType = AnalyticsEvents.PARAMETER_SHARE_DIALOG_CONTENT_UNKNOWN;
    }

    AppEventsLogger logger = AppEventsLogger.newLogger(context);
    Bundle parameters = new Bundle();
    parameters.putString(
            AnalyticsEvents.PARAMETER_SHARE_DIALOG_SHOW,
            displayType
    );
    parameters.putString(
            AnalyticsEvents.PARAMETER_SHARE_DIALOG_CONTENT_TYPE,
            contentType
    );
    logger.logSdkEvent(AnalyticsEvents.EVENT_SHARE_DIALOG_SHOW, null, parameters);
}
 
Example 12
Source File: LoginButton.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 13
Source File: FacebookProvider.java    From android with Apache License 2.0 4 votes vote down vote up
@Override
public void startActivity(Activity activity) {
    mLogger = AppEventsLogger.newLogger(activity);
}
 
Example 14
Source File: ApplicationModule.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
@Singleton @Provides AppEventsLogger provideAppEventsLogger() {
  return AppEventsLogger.newLogger(application);
}