-
Notifications
You must be signed in to change notification settings - Fork 625
Standardize support for Firebase products that integrate with Remote Config. #2222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f037c14
ffb9786
3fdff9f
10daf06
46fb82f
8268fe6
64f38af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,22 +16,41 @@ | |
|
||
import android.os.Bundle; | ||
import androidx.annotation.NonNull; | ||
import com.google.common.base.CaseFormat; | ||
import com.google.common.base.Converter; | ||
import com.google.firebase.analytics.connector.AnalyticsConnector; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.json.JSONObject; | ||
|
||
public class Personalization { | ||
public static final String ANALYTICS_ORIGIN_PERSONALIZATION = "fp"; | ||
public static final String ANALYTICS_PULL_EVENT = "_fpc"; | ||
public static final String ARM_KEY = "_fpid"; | ||
public static final String ARM_VALUE = "_fpct"; | ||
static final String PERSONALIZATION_ID = "personalizationId"; | ||
|
||
public static final String ANALYTICS_PULL_EVENT = "personalization_choice"; | ||
public static final String ARM_KEY = "arm_key"; | ||
vic-flair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public static final String ARM_VALUE = "arm_value"; | ||
public static final String PERSONALIZATION_ID = "personalization_id"; | ||
public static final String ARM_INDEX = "arm_index"; | ||
public static final String GROUP = "group"; | ||
|
||
public static final String ANALYTICS_PULL_EVENT_INTERNAL = "_fpc"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking (no action req'd): "_fpc" for the internal event name, and "_fpid" for the parameter name (in which to log the choice ID), aligns w the per-choice metadata design. |
||
public static final String CHOICE_ID = "choiceId"; | ||
public static final String CHOICE_ID_KEY = "_fpid"; | ||
|
||
private static final Converter<String, String> CONVERTER = | ||
vic-flair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CaseFormat.LOWER_UNDERSCORE.converterTo(CaseFormat.LOWER_CAMEL); | ||
|
||
/** The app's Firebase Analytics client. */ | ||
private final AnalyticsConnector analyticsConnector; | ||
|
||
/** A map of Remote Config parameter key to Personalization ID. */ | ||
private final Map<String, String> armsCache; | ||
vic-flair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** Creates an instance of {@code Personalization}. */ | ||
public Personalization(@NonNull AnalyticsConnector analyticsConnector) { | ||
this.analyticsConnector = analyticsConnector; | ||
armsCache = Collections.synchronizedMap(new HashMap<String, String>()); | ||
vic-flair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
|
@@ -58,9 +77,29 @@ public void logArmActive(@NonNull String key, @NonNull ConfigContainer configCon | |
return; | ||
} | ||
|
||
String personalizationId = metadata.optString(CONVERTER.convert(PERSONALIZATION_ID)); | ||
if (personalizationId.isEmpty()) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking: this won't break EAP usage because they aren't using the SDK |
||
} | ||
|
||
synchronized (armsCache) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mind adding a comment explaining why we need this? Thinking: this ensures we only log one event per param-choice pair. This map is bounded by the number of params. Choices are made on each fetch, so this isn't a long-lived cache. |
||
if (armsCache.get(key) == personalizationId) { | ||
return; | ||
} | ||
armsCache.put(key, personalizationId); | ||
} | ||
|
||
Bundle params = new Bundle(); | ||
vic-flair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
params.putString(ARM_KEY, metadata.optString(PERSONALIZATION_ID)); | ||
params.putString(ARM_KEY, key); | ||
params.putString(ARM_VALUE, values.optString(key)); | ||
params.putString(PERSONALIZATION_ID, personalizationId); | ||
params.putInt(ARM_INDEX, metadata.optInt(CONVERTER.convert(ARM_INDEX), -1)); | ||
params.putString(GROUP, metadata.optString(CONVERTER.convert(GROUP))); | ||
analyticsConnector.logEvent(ANALYTICS_ORIGIN_PERSONALIZATION, ANALYTICS_PULL_EVENT, params); | ||
vic-flair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Bundle paramsInternal = new Bundle(); | ||
paramsInternal.putString(CHOICE_ID_KEY, metadata.optString(CHOICE_ID)); | ||
analyticsConnector.logEvent( | ||
ANALYTICS_ORIGIN_PERSONALIZATION, ANALYTICS_PULL_EVENT_INTERNAL, paramsInternal); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.