com.facebook.appevents.AppEventsConstants Java Examples

The following examples show how to use com.facebook.appevents.AppEventsConstants. 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: Analytics.java    From openshop.io-android with MIT License 6 votes vote down vote up
/**
 * Method sends product view event to defined Analytics.
 *
 * @param remoteId remote id of the viewed product.
 * @param name     name of the viewed product.
 */
public static void logProductView(long remoteId, String name) {
    // FB event log
    Bundle parameters = new Bundle();
    parameters.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, PRODUCT);
    parameters.putLong(AppEventsConstants.EVENT_PARAM_CONTENT_ID, remoteId);
    parameters.putString(AppEventsConstants.EVENT_PARAM_DESCRIPTION, name);
    logFbEvent(AppEventsConstants.EVENT_NAME_VIEWED_CONTENT, null, parameters);

    // GA event log
    Map<String, String> event = new HitBuilders.EventBuilder()
            .setCategory(PRODUCT)
            .setAction("view")
            .setLabel("product with id: " + remoteId + ", name: " + name)
            .build();
    sendEventToAppTrackers(event);
}
 
Example #2
Source File: Analytics.java    From openshop.io-android with MIT License 6 votes vote down vote up
/**
 * Method sends "product add to cart" event to defined Analytics.
 *
 * @param remoteId       remote id of the viewed product.
 * @param name           name of the viewed product.
 * @param discountPrice product price.
 */
public static void logAddProductToCart(long remoteId, String name, double discountPrice) {
    // FB facebookLogger
    Bundle parameters = new Bundle();
    parameters.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, PRODUCT);
    parameters.putLong(AppEventsConstants.EVENT_PARAM_CONTENT_ID, remoteId);
    parameters.putString(AppEventsConstants.EVENT_PARAM_DESCRIPTION, name);
    logFbEvent(AppEventsConstants.EVENT_NAME_ADDED_TO_CART, discountPrice, parameters);

    // Ga
    Map<String, String> event = new HitBuilders.EventBuilder()
            .setCategory("ADDED_TO_CART")
            .setAction("ADDED_TO_CART")
            .setLabel("ADDED TO CART" + " product id: " + remoteId + " product name: " + name + " price: " + discountPrice)
            .build();
    sendEventToAppTrackers(event);
}
 
Example #3
Source File: Analytics.java    From openshop.io-android with MIT License 6 votes vote down vote up
/**
 * Method sends "user changed shop" event to defined Analytics.
 *
 * @param actualNonNullShop active shop before change.
 * @param newShopSelected   active shop after change.
 */
public static void logShopChange(Shop actualNonNullShop, Shop newShopSelected) {
    if (actualNonNullShop != null && newShopSelected != null) {
        String description = "From (id=" + actualNonNullShop.getId() + ",name=" + actualNonNullShop.getName() +
                ") to (id=" + newShopSelected.getId() + ",name=" + newShopSelected.getId() + ")";
        // FB facebookLogger
        Bundle parameters = new Bundle();
        parameters.putString(AppEventsConstants.EVENT_PARAM_DESCRIPTION, description);
        logFbEvent(AppEventsConstants.EVENT_NAME_UNLOCKED_ACHIEVEMENT, null, parameters);

        // Ga
        Map<String, String> event = new HitBuilders.EventBuilder()
                .setCategory("CHANGE_SHOP")
                .setAction("CHANGE_SHOP")
                .setLabel(description)
                .build();
        sendEventToAppTrackers(event);
    } else {
        Timber.e(new RuntimeException(), "Try log shop change with null parameters");
    }
}
 
Example #4
Source File: Analytics.java    From openshop.io-android with MIT License 6 votes vote down vote up
/**
 * Method sends "category view" event to Google Analytics.
 *
 * @param categoryId   id category for logging.
 * @param categoryName category name for logging.
 * @param isSearch     determine if normal category or search category.
 */
public static void logCategoryView(long categoryId, String categoryName, boolean isSearch) {
    Bundle parameters = new Bundle();
    parameters.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, "category");

    if (categoryId == 0) {
        Timber.e("Is categoryId = 0.");
    } else {
        parameters.putLong(AppEventsConstants.EVENT_PARAM_CONTENT_ID, categoryId);
        parameters.putString(AppEventsConstants.EVENT_PARAM_DESCRIPTION, categoryName);
        logFbEvent(AppEventsConstants.EVENT_NAME_VIEWED_CONTENT, null, parameters);

        Map<String, String> event = new HitBuilders.EventBuilder()
                .setCategory("VIEW_CATEGORY")
                .setAction(isSearch ? "SEARCH" : "VIEW_CATEGORY")
                .setLabel(isSearch ? "Search: " + categoryName : "CategoryId: " + categoryId + ". CategoryName: " + categoryName)
                .build();

        sendEventToAppTrackers(event);
    }
}
 
Example #5
Source File: LoginClient.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
boolean tryCurrentHandler() {
    LoginMethodHandler handler = getCurrentHandler();
    if (handler.needsInternetPermission() && !checkInternetPermission()) {
        addLoggingExtra(
            LoginLogger.EVENT_EXTRAS_MISSING_INTERNET_PERMISSION,
            AppEventsConstants.EVENT_PARAM_VALUE_YES,
            false
        );
        return false;
    }

    boolean tried = handler.tryAuthorize(pendingRequest);
    if (tried) {
        getLogger().logAuthorizationMethodStart(pendingRequest.getAuthId(),
                handler.getNameForLogging());
    } else {
        // We didn't try it, so we don't get any other completion
        // notification -- log that we skipped it.
        addLoggingExtra(
            LoginLogger.EVENT_EXTRAS_NOT_TRIED,
                handler.getNameForLogging(),
            true
        );
    }

    return tried;
}
 
Example #6
Source File: LoginManager.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private void logCompleteLogin(
        Context context,
        LoginClient.Result.Code result,
        Map<String, String> resultExtras,
        Exception exception,
        boolean wasLoginActivityTried,
        LoginClient.Request request) {
    LoginLogger loginLogger = LoginLoggerHolder.getLogger(context);
    if (loginLogger == null) {
        return;
    }
    if (request == null) {
        // We don't expect this to happen, but if it does, log an event for diagnostic purposes.
        loginLogger.logUnexpectedError(
                LoginLogger.EVENT_NAME_LOGIN_COMPLETE,
                "Unexpected call to logCompleteLogin with null pendingAuthorizationRequest."
        );
    } else {
        HashMap<String, String> pendingLoggingExtras = new HashMap<>();
        pendingLoggingExtras.put(
                LoginLogger.EVENT_EXTRAS_TRY_LOGIN_ACTIVITY,
                wasLoginActivityTried ?
                        AppEventsConstants.EVENT_PARAM_VALUE_YES :
                        AppEventsConstants.EVENT_PARAM_VALUE_NO
        );
        loginLogger.logCompleteLogin(
                request.getAuthId(),
                pendingLoggingExtras,
                result,
                resultExtras,
                exception);
    }
}
 
Example #7
Source File: FacebookProvider.java    From android with Apache License 2.0 5 votes vote down vote up
private void logEvent(String screen) {
    if (mLogger == null) return;

    Bundle parameters = new Bundle();
    parameters.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, screen);
    mLogger.logEvent(AppEventsConstants.EVENT_NAME_VIEWED_CONTENT, parameters);
}
 
Example #8
Source File: WebViewLoginMethodHandler.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
@Override
boolean tryAuthorize(final LoginClient.Request request) {
    Bundle parameters = new Bundle();
    if (!Utility.isNullOrEmpty(request.getPermissions())) {
        String scope = TextUtils.join(",", request.getPermissions());
        parameters.putString(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
        addLoggingExtra(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
    }

    DefaultAudience audience = request.getDefaultAudience();
    parameters.putString(
            ServerProtocol.DIALOG_PARAM_DEFAULT_AUDIENCE, audience.getNativeProtocolAudience());

    AccessToken previousToken = AccessToken.getCurrentAccessToken();
    String previousTokenString = previousToken != null ? previousToken.getToken() : null;
    if (previousTokenString != null
            && (previousTokenString.equals(loadCookieToken()))) {
        parameters.putString(
                ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN,
                previousTokenString);
        // Don't log the actual access token, just its presence or absence.
        addLoggingExtra(
                ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN,
                AppEventsConstants.EVENT_PARAM_VALUE_YES);
    } else {
        // The call to clear cookies will create the first instance of CookieSyncManager if
        // necessary
        Utility.clearFacebookCookies(loginClient.getActivity());
        addLoggingExtra(
                ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN,
                AppEventsConstants.EVENT_PARAM_VALUE_NO);
    }

    WebDialog.OnCompleteListener listener = new WebDialog.OnCompleteListener() {
        @Override
        public void onComplete(Bundle values, FacebookException error) {
            onWebDialogComplete(request, values, error);
        }
    };

    e2e = LoginClient.getE2E();
    addLoggingExtra(ServerProtocol.DIALOG_PARAM_E2E, e2e);

    FragmentActivity fragmentActivity = loginClient.getActivity();
    WebDialog.Builder builder = new AuthDialogBuilder(
            fragmentActivity,
            request.getApplicationId(),
            parameters)
            .setE2E(e2e)
            .setIsRerequest(request.isRerequest())
            .setOnCompleteListener(listener)
            .setTheme(FacebookSdk.getWebDialogTheme());
    loginDialog = builder.build();

    FacebookDialogFragment dialogFragment = new FacebookDialogFragment();
    dialogFragment.setRetainInstance(true);
    dialogFragment.setDialog(loginDialog);
    dialogFragment.show(fragmentActivity.getSupportFragmentManager(),
            FacebookDialogFragment.TAG);

    return true;
}
 
Example #9
Source File: Analytics.java    From openshop.io-android with MIT License 4 votes vote down vote up
/**
 * Method sends "order created" event to Google Analytics.
 *
 * @param orderCart        ordered cart content.
 * @param orderRemoteId    remote order id.
 * @param orderTotalPrice  total order price.
 * @param selectedShipping selected shipping to log its price.
 */
public static void logOrderCreatedEvent(Cart orderCart, String orderRemoteId, Double orderTotalPrice, Shipping selectedShipping) {
    //GA
    Map<String, String> eventPostOrder = new HitBuilders.EventBuilder()
            .setCategory(POST_ORDER)
            .setAction(POST_ORDER)
            .setLabel(POST_ORDER)
            .build();
    sendEventToAppTrackers(eventPostOrder);

    // Send GA whole cart
    Map<String, String> event = new HitBuilders.TransactionBuilder()
            .setTransactionId(orderRemoteId)
            .setAffiliation(SettingsMy.getActualNonNullShop(null).getName())
            .setRevenue(orderTotalPrice)
            .setTax(0.0)
            .setShipping(selectedShipping.getPrice())
            .setCurrencyCode(orderCart.getCurrency())
            .build();
    sendEventToAppTrackers(event);

    // Fb event whole cart
    Bundle parametersCheckout = new Bundle();
    parametersCheckout.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, "cart");
    parametersCheckout.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, orderRemoteId);
    parametersCheckout.putInt(AppEventsConstants.EVENT_PARAM_NUM_ITEMS, orderCart.getItems().size());  // Unique products/events
    parametersCheckout.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, orderCart.getCurrency());
    logFbEvent(AppEventsConstants.EVENT_NAME_INITIATED_CHECKOUT, orderTotalPrice, parametersCheckout);

    // Fb event shipping
    Bundle parametersShip = new Bundle();
    parametersShip.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, "shipping");
    parametersShip.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, orderRemoteId);
    parametersShip.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, orderCart.getCurrency());
    logFbEvent(AppEventsConstants.EVENT_NAME_PURCHASED, (double) selectedShipping.getPrice(), parametersShip);

    // Send single products in cart to GA and FB
    for (int i = 0; i < orderCart.getItems().size(); i++) {
        CartProductItem item = orderCart.getItems().get(i);

        Double price = item.getVariant().getPrice();
        if (item.getVariant().getDiscountPrice() > 0) {
            price = item.getVariant().getDiscountPrice();
        }
        Map<String, String> eventSingle = new HitBuilders.ItemBuilder()
                .setTransactionId(orderRemoteId)
                .setName(item.getVariant().getName())
                .setSku("Product id: " + item.getVariant().getRemoteId())
                .setCategory("Category id: " + item.getVariant().getCategory())
                .setPrice(price)
                .setQuantity(item.getQuantity())
                .setCurrencyCode(orderCart.getCurrency())
                .build();
        sendEventToAppTrackers(eventSingle);

        // Fb events purchased
        Bundle parameters = new Bundle();
        parameters.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, PRODUCT);
        parameters.putLong(AppEventsConstants.EVENT_PARAM_CONTENT_ID, item.getVariant().getRemoteId());
        parameters.putInt(AppEventsConstants.EVENT_PARAM_NUM_ITEMS, item.getQuantity());
        parameters.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, orderCart.getCurrency());
        logFbEvent(AppEventsConstants.EVENT_NAME_PURCHASED, price * item.getQuantity(), parameters);
    }
}