4

I have a single Activity, with multiple Fragments in a ViewPager.

Currently, this is my way, to send screen view event to both Google Analytics and Firebase


public static void trackView(Activity activity, String view) {
    trackFBView(activity, view);
    trackGAView(view);
}

private static void trackFBView(Activity activity, String view) {
    if (activity == null) {
        return;
    }

    FirebaseAnalytics firebaseAnalytics = getFirebaseAnalytics();
    if (firebaseAnalytics == null) {
        return;
    }

    firebaseAnalytics.setCurrentScreen(activity, view, null);
}

private static void trackGAView(String view) {
    Tracker tracker = Utils.getTracker();
    if (tracker == null) {
        return;
    }
    tracker.setScreenName(view);
    tracker.send(new HitBuilders.ScreenViewBuilder().build());
}

public static FirebaseAnalytics getFirebaseAnalytics() {
    if (false == isGooglePlayServicesAvailable()) {
        return null;
    }

    return FirebaseAnalytics.getInstance(JStockApplication.instance());
}

In my ViewPager's listener, this is how I send the screen view event.

private ViewPager.OnPageChangeListener getOnPageChangeListener() {
    return new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {

            if (position == 0) {
                Utils.trackView(DetailedStockFragmentActivity.this, "InfoFragment");

After some testing, I realize I do receive screen view event in GA, but not in Firebase.

Later, I realize firebaseAnalytics.setCurrentScreen doesn't actually send a screen view event to Firebase. firebaseAnalytics.setCurrentScreen merely prepare an implicit parameter. It will only sent across to firebase, during the next event.

Currently, in my fragments, I didn't fire any events explicitly.

I was wondering, in order to help Firebase make better prediction (Help Firebase to identify user in looking at which screen), I was wondering, should I send "Screen View" event explicitly as follow?

private static void trackFBView(Activity activity, String view) {
    if (activity == null) {
        return;
    }

    FirebaseAnalytics firebaseAnalytics = getFirebaseAnalytics();
    if (firebaseAnalytics == null) {
        return;
    }

    firebaseAnalytics.setCurrentScreen(activity, view, null);

    // Question: Should I do this to help Firebase makes better prediction?
    firebaseAnalytics.logEvent(view + "_ScreenView", null);
}
Sree
  • 1,694
  • 1
  • 18
  • 29
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875

1 Answers1

4

I think there are a few misunderstandings here.

First, as you've noticed, setCurrentScreen creates a parameter that is automatically attached to future events. Events are the only things sent to Firebase and have parameters attached—a parameter can only exist in relation to an event. "Screen parameters" are a little bit more special than normal parameters since they appear in crash reporting logs and you can more easily use them to create audiences. This answer sums up what I've just said nicely.

The second misunderstanding is about how Firebase Predictions works. Predictions as of today can only operate on events. That is, if you create a custom prediction, it won't use any parameters and can only predict whether or not a user will perform an action (event).

For your case, I would need to know more about what you're trying to do. If you're looking for user engagement, that's already baked in with the "churn" prediction. (And no, logging an analytics event won't affect the prediction since it's based off of a global "is the user using this app" idea.) Now, on the other hand, if you're trying to know whether or not a user is using a part of your app, then you would create a custom event like select_stock and use Predictions to guess whether or not a user is going to view a stock. I like to think of Predictions or A/B testing as being used to measure either engagement or an increase in a specific action being performed.

As a general rule of thumb, you should pepper your app with user actions instead of passive viewership. For example, you could have an action for when a user selects a stock, favorites it, shares it, searches for it, etc. Then, in Predictions or A/B testing, you can see how a change you've made is affecting a specific piece of the user's overall engagement—"Is the user doing more or less of X?"

TL;DR: No, logging events doesn't affect the churn prediction since they are a general, "Is this app predicted to be used in the next 7 days or not?" However, you could be trying to figure out if a user is going to perform more or less of a certain action and then log an event for that to be used in Predictions or A/B testing.

Info on predefined predictions, an overview of using the predictions feature, and a talk with full length example of how predictions can be used.

Edit, answering comment:

I'd like to preface this by saying that I'm not a Firebase engineer and I doubt Googlers will share their trade secrets with you, so I'm mostly guessing here. I'm going to use a checkout example since that's the easiest one I could think of.

Ok, to try and make sense of Predictions, we need to understand a little bit of machine learning first. ML models are kinda dumb if you think about it: they're just trying to map a set of inputs to some output numbers (probabilities). Since Predictions doesn't accept event parameters, I would guess that Google's feeding in the sequence of analytics events that occured during a given user session. AFAIK, the order in which inputs are supplied to an ML model doesn't matter so the order in which the events occur won't be taken into account (Google might have figured a way around that, dunno).

With our assumptions about the ML model in hand, we can come back to our checkout example. Basically, I think you'll actually be mistraining or at least logging meaningless events by just tracking which screens the user visits. Let's say the user goes through the "Cart," "Enter your address," and "Checkout" screens. In that case, the model is going to train itself to see that those sets of events are highly correlated with a purchase.

You might think, "Well, that's great!" Not so fast, that kind of prediction is useless since it isn't actually predicting anything. It's just saying, "Oh look, a user who makes it to the checkout screen usually buys stuff." I would think that logging screen events would actually make your predictions worse in this case: let's say a user visits the checkout screen, but then leaves because they're scared of giving you their credit card or something. The model is going to think, "They visited that screen, so they're totally gonna buy stuff," but that's wrong.

No on the other hand, it makes sense to me that logging user actions as I mentioned before would be much more useful. For example, a more accurate prediction that would actually predict stuff could be trained using the number of item_added_to_card events. The more items a user adds to their cart, the more committed they probably are to buying stuff.

Again, I don't know much about your app, but logging clicks events to see a detailed article pane, liking the article, or sharing it seem to me like they could provide more insights than simply viewing the articles pane. However, I think it depends on what kind of user behavior you have. If most of your users who've purchased stuff also spend a bunch of time on the article screen, then yeah, I don't see how it could hurt to log an event.

The general point I'm trying to get across is that I think Predictions will do better with events that measure user engagement. So passive viewership could work, but what if some users like to just keep that screen open, or maybe the articles view is even your default tab? Then it doesn't really give the model any new information since almost all your users will go through that screen. My rule of thumb is, "If a user clicks on it, log it." Then you're sure to get tons of analytics events for the ML model to find patterns in, like users who click to see articles are more likely to buy stuff.

PS: reverse engineering this kind of model is hard and I could be totally wrong in my assumptions.

SUPERCILEX
  • 3,929
  • 4
  • 32
  • 61
  • But, it is strange that Firebase prediction can make accurate prediction, without providing screen information for learning purpose. For example, in reality, users who looks at `StockNewsFragment`, are more likely to perform `in_app_purchase` than the users who look at `StockChartFragment`. Without providing accurate screen view information, how does Firebase prediction is going to predict, whether a user is likely to perform `in_app_purchase` ? – Cheok Yan Cheng Dec 31 '17 at 11:06
  • See my updated answer, it was way too long to fit in a comment. – SUPERCILEX Jan 01 '18 at 01:30
  • Laurence just posted [this article](https://medium.com/@lmoroney_40129/machine-learning-in-firebase-using-predictions-8a1df0c63b60) which confirms that Predictions is using TensorFlow, but doesn't elaborate much. – SUPERCILEX Jan 12 '18 at 00:36