From 6e0fd6b77759baf43cb37d407041be051b4856b5 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Wed, 4 Nov 2015 20:44:25 -0800 Subject: Route all existing screen view events through the Logger * The logger is responsible for sending it to its logging implementation, and also to AnalyicsUtil. * Standardize logic for creating a tagged version of a screen name Bug: 23164804 Change-Id: I9b817fba5359f78340f2d9fdba54af9ea73cdb37 --- src/com/android/dialer/logging/Logger.java | 51 ++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 7 deletions(-) (limited to 'src/com/android/dialer/logging/Logger.java') diff --git a/src/com/android/dialer/logging/Logger.java b/src/com/android/dialer/logging/Logger.java index 300707779..ee23dc8e7 100644 --- a/src/com/android/dialer/logging/Logger.java +++ b/src/com/android/dialer/logging/Logger.java @@ -17,11 +17,18 @@ package com.android.dialer.logging; import android.app.Activity; +import android.app.Fragment; +import android.text.TextUtils; +import com.android.contacts.commonbind.analytics.AnalyticsUtil; import com.android.dialerbind.ObjectFactory; import com.android.incallui.Call; +/** + * Single entry point for all logging/analytics-related work for all user interactions. + */ public abstract class Logger { + public static final String FRAGMENT_TAG_SEPARATOR = "#"; public static Logger getInstance() { return ObjectFactory.getLoggerInstance(); @@ -40,19 +47,49 @@ public abstract class Logger { } /** - * Logs an event indicating that a screen/fragment was displayed. + * Logs an event indicating that a fragment was displayed. + * + * @param fragment to log an event for. + */ + public static void logFragmentView(Fragment fragment) { + if (fragment == null) { + return; + } + + logScreenView(fragment.getClass().getSimpleName(), fragment.getActivity(), null); + } + + /** + * Logs an event indicating that a screen was displayed. * - * @param fragmentName of the displayed fragment. - * @param activity Parent activity of the fragment. - * @param tag Optional string used to provide additional information about the fragment. + * @param screenName of the displayed screen. + * @param activity Parent activity of the displayed screen. + * @param tag Optional string used to provide additional information about the screen. */ - public static void logScreenView(String fragmentName, Activity activity, String tag) { + public static void logScreenView(String screenName, Activity activity, String tag) { final Logger logger = getInstance(); if (logger != null) { - logger.logScreenViewImpl(fragmentName, activity, tag); + logger.logScreenViewImpl(getScreenNameWithTag(screenName, tag)); + } + + AnalyticsUtil.sendScreenView(screenName, activity, tag); + } + + /** + * Build a tagged version of the provided screenName if the tag is non-empty. + * + * @param screenName Name of the screen. + * @param tag Optional tag describing the screen. + * @return the unchanged screenName if the tag is {@code null} or empty, the tagged version of + * the screenName otherwise. + */ + public static String getScreenNameWithTag(String screenName, String tag) { + if (TextUtils.isEmpty(tag)) { + return screenName; } + return screenName + FRAGMENT_TAG_SEPARATOR + tag; } public abstract void logCallImpl(Call call); - public abstract void logScreenViewImpl(String fragmentName, Activity activity, String tag); + public abstract void logScreenViewImpl(String screenName); } -- cgit v1.2.3