public class Apptimize
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Apptimize.OnExperimentRunListener
Interface definition for a callback to be invoked when an Apptimize A/B
experiment is run.
|
static interface |
Apptimize.OnExperimentsProcessedListener
Interface definition for a callback to be invoked when an Apptimize A/B
experiment configuration is recalculated.
|
Modifier and Type | Method and Description |
---|---|
static void |
addOnExperimentsProcessedListener(Apptimize.OnExperimentsProcessedListener l)
Add a callback to be invoked when an Apptimize configuration is recalculated.
|
static void |
addToMetric(java.lang.String metricName,
double value)
Deprecated.
Use
track(String, double) instead. |
static void |
clearAllForcedVariants()
Stop forcing variants.
|
static void |
clearForcedVariant(java.lang.Long variantId)
Stop forcing the variant with the given Id.
|
static void |
clearUserAttribute(java.lang.String attributeName)
Erase a user attribute from memory so it's no longer used for targeting/filtering/segmenting.
|
static void |
disable()
Disables Apptimize.
|
static double |
doubleForTest(java.lang.String varName,
double defaultValue)
Get the
double associated with an Apptimize variable. |
static double |
doubleForTest(java.lang.String varName,
double defaultValue,
ApptimizeOptions options)
Get the
double associated with an Apptimize variable. |
static void |
event(java.lang.String eventName)
Deprecated.
Use
track(String) instead. |
static void |
event(java.lang.String eventName,
double value)
Deprecated.
Use
track(String, double) instead. |
static void |
forceVariant(java.lang.Long variantId)
Force the variant with the given ID to be enabled.
|
static java.lang.String |
getApptimizeAnonUserId()
Get the current Apptimize-created anonymous user ID
|
static java.lang.String |
getCustomerUserId()
Get the current customer-specified userId
|
static java.lang.String |
getExperimentString(java.lang.String varName,
java.lang.String defaultValue)
Deprecated.
Use
stringForTest(String, String) instead. |
static java.lang.String |
getPilotTargetingId() |
static java.util.Map<java.lang.String,ApptimizeTestInfo> |
getTestInfo()
Returns information about all Apptimize A/B tests and Feature Flags that
the device is enrolled in.
|
static java.util.Map<java.lang.String,ApptimizeTestInfo> |
getTestInfo(ApptimizeOptions options)
Returns information about all Apptimize A/B tests and Feature Flags that the device is
enrolled in.
|
static java.lang.String |
getUserId()
Deprecated.
Use
getApptimizeAnonUserId() instead. |
static java.util.Map<java.lang.Long,java.util.Map<java.lang.String,java.lang.Object>> |
getVariants()
return information about all variants launched.
|
static java.util.Map<java.lang.Long,java.util.Map<java.lang.String,java.lang.Object>> |
getVariants(ApptimizeOptions options)
return information about all variants launched.
|
static void |
goalAchieved(java.lang.String goalName)
Inform Apptimize a metric was achieved.
|
static int |
integerForTest(java.lang.String varName,
int defaultValue)
Get the
int associated with an Apptimize variable. |
static int |
integerForTest(java.lang.String varName,
int defaultValue,
ApptimizeOptions options)
Get the
int associated with an Apptimize variable. |
static boolean |
isFeatureFlagOn(java.lang.String name) |
static boolean |
isFeatureFlagOn(java.lang.String name,
ApptimizeOptions options) |
static void |
metricAchieved(java.lang.String metricName)
Inform Apptimize a metric was achieved.
|
static void |
removeOnExperimentsProcessedListener(Apptimize.OnExperimentsProcessedListener l)
Remove an observer to be invoked when an Apptimize configuration is recalculated.
|
static void |
reset()
Simulates a fresh install of Apptimize.
|
static void |
reset(boolean setupAgain) |
static void |
runExperiment(java.lang.String experimentName,
ApptimizeExperiment experiment)
Executes an experiment.
|
static void |
runTest(java.lang.String testName,
ApptimizeTest test)
Executes a code block test.
|
static void |
runTest(java.lang.String testName,
ApptimizeTest test,
ApptimizeOptions options)
Executes a code block test.
|
static void |
setActiveCodeBlockForExperiment(java.lang.String experimentName,
java.lang.String variationMethodName)
Set the active code block for a specific experiment
|
static <T> void |
setActiveValueForDynamicVariable(ApptimizeVar<T> dynVar,
T value)
Set the active value for a dynamic variable
|
static void |
setCustomerUserId(java.lang.String customerUserId)
Set the current customer-specified user ID
|
static void |
setMetric(java.lang.String metricName,
double value)
Deprecated.
Use
track(String, double) instead. |
static void |
setOffline(boolean offline)
Set whether Apptimize should be in offline mode.
|
static void |
setOnExperimentRunListener(Apptimize.OnExperimentRunListener l)
Register a callback to be invoked when an Apptimize A/B test is run.
|
static void |
setPilotTargetingId(java.lang.String id) |
static void |
setTestmodeActive(boolean mode)
Activate the Apptimize SDK test mode (used for unit testing)
|
static void |
setup(android.content.Context context,
java.lang.String appKey)
Initializes Apptimize with the default options.
|
static void |
setup(android.content.Context context,
java.lang.String appKey,
ApptimizeOptions options)
Initializes Apptimize with the given options.
|
static void |
setUserAttribute(java.lang.String attributeName,
boolean value)
Set a user attribute to be used in targeting/filtering/segmenting.
|
static void |
setUserAttribute(java.lang.String attributeName,
double number)
Set a user attribute to be used in targeting/filtering/segmenting.
|
static void |
setUserAttribute(java.lang.String attributeName,
int number)
Set a user attribute to be used in targeting/filtering/segmenting.
|
static void |
setUserAttribute(java.lang.String attributeName,
java.lang.String string)
Set a user attribute to be used in targeting/filtering/segmenting.
|
static java.lang.String |
stringForTest(java.lang.String varName,
java.lang.String defaultValue)
Get the
String associated with an Apptimize variable. |
static java.lang.String |
stringForTest(java.lang.String varName,
java.lang.String defaultValue,
ApptimizeOptions options)
Get the
String associated with an Apptimize variable. |
static void |
track(java.lang.String eventName)
Inform Apptimize that an event occurred.
|
static void |
track(java.lang.String eventName,
double value)
Inform Apptimize that an event occurred.
|
public static void setup(android.content.Context context, java.lang.String appKey)
context
- Your Context object (e.g., your Application or Activity).
Usually just "this".appKey
- The key provided to you by Apptimize. It links your app to
your Apptimize account.public static void setup(android.content.Context context, java.lang.String appKey, ApptimizeOptions options)
context
- Your Context object (e.g., your Application or Activity).
Usually just "this".appKey
- The key provided to you by Apptimize. It links your app to
your Apptimize account.options
- Options for configuring Apptimize. See
ApptimizeOptions
public static void reset()
public static void reset(boolean setupAgain)
public static void disable()
setup(android.content.Context, String)
method is called.
If setup(android.content.Context, String)
method has not been called yet, this disable method
does nothing.
Note that this disable method is only activated the moment it is called. Any events after
setup(android.content.Context, String)
is called, and prior to this disable method is called,
will still be tracked.public static void setOffline(boolean offline)
Set whether Apptimize should be in offline mode.
The default value for this setting is false. If set to true, Apptimize will not receive or send data until this setting is reset to false. This setting will persist across app restarts; e.g., if it is set to true and the app is restarted, Apptimize will still be in offline mode until this method is called with a value of false.
You may call this method before or after the Apptimize.setup() call. However, note that if you call this method and then do not call Apptimize.setup() before the app is destroyed, your requested setting will NOT be persisted for the next time the app is created.
offline
- True to request offline mode, or false to reset to online mode.public static void forceVariant(java.lang.Long variantId)
variantId
- The variantId to be forced.public static void clearForcedVariant(java.lang.Long variantId)
variantId
- The variantId to stop forcing.forceVariant(java.lang.Long)
public static void clearAllForcedVariants()
forceVariant(java.lang.Long)
public static void setUserAttribute(java.lang.String attributeName, boolean value)
attributeName
- The attribute's name/key.value
- The value of the attribute.public static void setUserAttribute(java.lang.String attributeName, double number)
attributeName
- The attribute's name/key.number
- The value of the attribute.public static void setUserAttribute(java.lang.String attributeName, int number)
attributeName
- The attribute's name/key.number
- The value of the attribute.public static void setUserAttribute(java.lang.String attributeName, java.lang.String string)
string
parameter) has
the same effect as calling clearUserAttribute.attributeName
- The attribute's name/key.string
- The value of the attribute.public static void clearUserAttribute(java.lang.String attributeName)
attributeName
- The attribute's name/key.public static void setPilotTargetingId(java.lang.String id)
public static java.lang.String getPilotTargetingId()
public static boolean isFeatureFlagOn(java.lang.String name)
public static boolean isFeatureFlagOn(java.lang.String name, ApptimizeOptions options)
public static void runTest(java.lang.String testName, ApptimizeTest test, ApptimizeOptions options)
ApptimizeVar
(whose value can be
changed by A/B experiments) and then having an if/else or switch
statement based on the value of the ApptimizeVar
.
Options can be configured using the input ApptimizeOptions.testName
- The name of the test you're running.test
- The code for the test. If the test is not
currently running, the baseline method will be run.options
- Options for configuring this method. See
ApptimizeOptions
public static void runTest(java.lang.String testName, ApptimizeTest test)
ApptimizeVar
(whose value can be
changed by A/B experiments) and then having an if/else or switch
statement based on the value of the ApptimizeVar
.
This method's options can be configured by instead calling
runTest(String, ApptimizeTest, ApptimizeOptions)
.testName
- The name of the test you're running.test
- The code for the test. If the test is not
currently running, the baseline method will be run.public static void runExperiment(java.lang.String experimentName, ApptimizeExperiment experiment)
ApptimizeVar
(whose value can be
changed by A/B experiments) and then having an if/else or switch
statement based on the value of the ApptimizeVar
.
Note: This method will soon be deprecated. Use
runTest(String, ApptimizeTest)
instead.
This method's options can be configured by instead calling
runTest(String, ApptimizeTest, ApptimizeOptions)
.experimentName
- The name of the experiment you're running.experiment
- The code for the experiment. If the experiment is not
currently running, the baseline method will be run.public static java.lang.String stringForTest(java.lang.String varName, java.lang.String defaultValue, ApptimizeOptions options)
Get the String
associated with an Apptimize variable. Calling
this method is the equivalent of defining an
ApptimizeVar
using
ApptimizeVar.createString(String, String)
and then calling its
ApptimizeVar.value()
method.
Note that this method will likely be deprecated soon in favor of using
ApptimizeVar
directly.
Options can be configured using the input ApptimizeOptions.
varName
- The name of the Apptimize variable.defaultValue
- The value to return if this device is not enrolled in any A/B
experiments that affect this variable.options
- Options for configuring this method. See
ApptimizeOptions
String
value this device should use for this A/B test
variable.public static java.lang.String stringForTest(java.lang.String varName, java.lang.String defaultValue)
Get the String
associated with an Apptimize variable. Calling
this method is the equivalent of defining an
ApptimizeVar
using
ApptimizeVar.createString(String, String)
and then calling its
ApptimizeVar.value()
method.
Note that this method will likely be deprecated soon in favor of using
ApptimizeVar
directly.
This method's options can be configured by instead calling
stringForTest(String, String, ApptimizeOptions)
.
varName
- The name of the Apptimize variable.defaultValue
- The value to return if this device is not enrolled in any A/B
experiments that affect this variable.String
value this device should use for this A/B test
variable.@Deprecated public static java.lang.String getExperimentString(java.lang.String varName, java.lang.String defaultValue)
stringForTest(String, String)
instead.
Get the String
associated with an Apptimize variable. Calling
this method is the equivalent of defining an
ApptimizeVar
using
ApptimizeVar.createString(String, String)
and then calling its
ApptimizeVar.value()
method.
Note that this method will likely be deprecated soon in favor of using
ApptimizeVar
directly.
This method's options can be configured by instead calling
stringForTest(String, String, ApptimizeOptions)
.
varName
- The name of the Apptimize variable.defaultValue
- The value to return if this device is not enrolled in any A/B
experiments that affect this variable.String
value this device should use for this A/B test
variable.public static double doubleForTest(java.lang.String varName, double defaultValue, ApptimizeOptions options)
Get the double
associated with an Apptimize variable. Calling
this method is the equivalent of defining an
ApptimizeVar
using
ApptimizeVar.createDouble(String, Double)
and then calling its
ApptimizeVar.value()
method.
Note that this method will likely be deprecated soon in favor of using
ApptimizeVar
directly.
Options can be configured using the input ApptimizeOptions.
varName
- The name of the Apptimize variable.defaultValue
- The value to return if this device is not enrolled in any A/B
experiments that affect this variable.options
- Options for configuring this method. See
ApptimizeOptions
double
value this device should use for this A/B test
variable.public static double doubleForTest(java.lang.String varName, double defaultValue)
Get the double
associated with an Apptimize variable. Calling
this method is the equivalent of defining an
ApptimizeVar
using
ApptimizeVar.createDouble(String, Double)
and then calling its
ApptimizeVar.value()
method.
Note that this method will likely be deprecated soon in favor of using
ApptimizeVar
directly.
This method's options can be configured by instead calling
doubleForTest(String, double, ApptimizeOptions)
varName
- The name of the Apptimize variable.defaultValue
- The value to return if this device is not enrolled in any A/B
experiments that affect this variable.double
value this device should use for this A/B test
variable.public static int integerForTest(java.lang.String varName, int defaultValue, ApptimizeOptions options)
Get the int
associated with an Apptimize variable. Calling
this method is the equivalent of defining an
ApptimizeVar
using
ApptimizeVar.createInteger(String, Integer)
and then calling its
ApptimizeVar.value()
method.
Note that this method will likely be deprecated soon in favor of using
ApptimizeVar
directly.
Options can be configured using the input ApptimizeOptions.
varName
- The name of the Apptimize variable.defaultValue
- The value to return if this device is not enrolled in any A/B
experiments that affect this variable.options
- Options for configuring this method. See
ApptimizeOptions
int
value this device should use for this A/B test
variable.public static int integerForTest(java.lang.String varName, int defaultValue)
Get the int
associated with an Apptimize variable. Calling
this method is the equivalent of defining an
ApptimizeVar
using
ApptimizeVar.createInteger(String, Integer)
and then calling its
ApptimizeVar.value()
method.
Note that this method will likely be deprecated soon in favor of using
ApptimizeVar
directly.
This method's options can be configured by instead calling
integerForTest(String, int, ApptimizeOptions)
.
varName
- The name of the Apptimize variable.defaultValue
- The value to return if this device is not enrolled in any A/B
experiments that affect this variable.int
value this device should use for this A/B test
variable.public static void track(java.lang.String eventName)
Inform Apptimize that an event occurred. For noteworthy events that you wish to track, you should call this method each time the event occurs. This data will then be displayed in your results at apptimize.com. Examples of events you could track include: purchases being made, login events, and Facebook shares.
If there is a numeric value associated with this event that you'd like to
track and view at apptimize.com, use track(String, double)
instead.
eventName
- The event's name.public static void track(java.lang.String eventName, double value)
Inform Apptimize that an event occurred. For noteworthy events that you wish to track, you should call this method each time the event occurs. This data will then be displayed in your results at apptimize.com. Examples of events you could track include: purchases being made, login events, and Facebook shares.
If there is a numeric value associated with this event that you'd like to
track and view at apptimize.com, provide it as the input parameter
value
. For example, if the event is a purchase, the value
might be the price. If there is no such value, use track(String)
instead.
eventName
- The event's name.value
- The numeric value associated with this event.public static void event(java.lang.String eventName)
track(String)
instead.Inform Apptimize that an event occurred. For noteworthy events that you wish to track, you should call this method each time the event occurs. This data will then be displayed in your results at apptimize.com. Examples of events you could track include: purchases being made, login events, and Facebook shares.
If there is a numeric value associated with this event that you'd like to
track and view at apptimize.com, use track(String, double)
instead.
eventName
- The event's name.public static void event(java.lang.String eventName, double value)
track(String, double)
instead.Inform Apptimize that an event occurred. For noteworthy events that you wish to track, you should call this method each time the event occurs. This data will then be displayed in your results at apptimize.com. Examples of events you could track include: purchases being made, login events, and Facebook shares.
If there is a numeric value associated with this event that you'd like to
track and view at apptimize.com, provide it as the input parameter
value
. For example, if the event is a purchase, the value
might be the price. If there is no such value, use track(String)
instead.
eventName
- The event's name.value
- The numeric value associated with this event.public static void goalAchieved(java.lang.String goalName)
track(String)
instead.goalName
- The metric's name.public static void metricAchieved(java.lang.String metricName)
track(String)
instead.metricName
- The metric's name.public static void setMetric(java.lang.String metricName, double value)
track(String, double)
instead.Inform Apptimize that a numeric metric was achieved. A numeric metric is a noteworthy event associated with a numeric value that you wish to track. Call this whenever a numeric metric has been achieved, and this data will then be displayed in your results at apptimize.com.
For example, if the event you're interested in is a purchase event, you
could call this method when a purchase is made and provide the price as
the value
. Then when viewing your results at apptimize.com you
would be able to see the sum of the purchase prices.
metricName
- The metric's name.value
- The numeric value associated with this metric event.public static void addToMetric(java.lang.String metricName, double value)
track(String, double)
instead.Inform Apptimize that a numeric metric was achieved. A numeric metric is a noteworthy event associated with a numeric value that you wish to track. Call this whenever a numeric metric has been achieved, and this data will then be displayed in your results at apptimize.com.
For example, if the event you're interested in is a purchase event, you
could call this method when a purchase is made and provide the price as
the value
. Then when viewing your results at apptimize.com you
would be able to see the sum of the purchase prices.
metricName
- The metric's name.value
- The numeric value associated with this metric event.public static java.util.Map<java.lang.String,ApptimizeTestInfo> getTestInfo()
Returns information about all Apptimize A/B tests and Feature Flags that the device is enrolled in. Note that this does NOT include information about Apptimize A/B tests or Feature Flags that are running but that this device is not enrolled in.
The returned Map
will contain one entry for each A/B
test and Feature Flag that the device is enrolled in. The key will be the
name of the test or Feature Flag, and the value will be the ApptimizeTestInfo
containing information about this test. The return will be empty if this
device is enrolled in no tests.
Note that it is also possible for this method to return null
if
no information could be returned; e.g., in the case where this method is
called before setup(android.content.Context, String)
is
called.
Map
with a
ApptimizeTestInfo
for each A/B test and Feature Flag that the
device is enrolled in, or null
if no information could be returned.public static java.util.Map<java.lang.String,ApptimizeTestInfo> getTestInfo(ApptimizeOptions options)
Returns information about all Apptimize A/B tests and Feature Flags that the device is enrolled in. Note that this does NOT include information about Apptimize A/B tests or Feature Flags that are running but that this device is not enrolled in.
The returned Map
will contain one entry for each A/B test and Feature Flag
that the device is enrolled in. The key will be the name of the test or Feature Flag
and the value will be the ApptimizeTestInfo
containing information about this test. The return will be empty if this
device is enrolled in no tests.
Note that it is also possible for this method to return null
if
no information could be returned; e.g., in the case where this method is
called before setup(android.content.Context, String)
is
called.
options
- Options for configuring this method. See
ApptimizeOptions
Map
with a
ApptimizeTestInfo
for each A/B test and Feature Flag
that the device is enrolled in, or null
if this information
could not be returned.public static java.util.Map<java.lang.Long,java.util.Map<java.lang.String,java.lang.Object>> getVariants()
return information about all variants launched.
The returned Map
will contain one entry for each variant in a currently
running experiment. The returned Map
will have the key as the variant's ID,
and the value as another Map
that maps String
key to
their corresponding Object
values:
("variantId" : Long, "variantName" : String, "experimentId" : Long, "experimentName" : String).
The return will be empty if there are no running experiments.
Note that it is also possible for this method to return null
if
no information could be returned; e.g., in the case where this method is
called before setup(android.content.Context, String)
is
called.
Map
for each variant launched, or null
if this information could not be foundpublic static java.util.Map<java.lang.Long,java.util.Map<java.lang.String,java.lang.Object>> getVariants(ApptimizeOptions options)
return information about all variants launched.
The returned Map
will contain one entry for each variant in a currently
running experiment. The returned Map
will have the key as the variant's ID,
and the value as another Map
that maps String
key to
their corresponding Object
values:
("variantId" : Long, "variantName" : String, "experimentId" : Long, "experimentName" : String).
The return will be empty if there are no running experiments.
In rare cases where results come from old verions of Apptimize, the field 'experimentId' may be null;
Note that it is also possible for this method to return null
if
no information could be returned; e.g., in the case where this method is
called before setup(android.content.Context, String)
is
called.
options
- Options for configuring this method. See
ApptimizeOptions
Map
for each variant launched, or null
if this information could not be foundpublic static java.lang.String getUserId()
getApptimizeAnonUserId()
instead.String
user ID that uniquely identifies
this device to Apptimize. This method will return null
if the
user ID could not be returned; e.g., in the case where this method is
called before setup(android.content.Context, String)
is
called. In rare cases this method could return the empty string, like in
the case where you have remotely disabled the Apptimize library.String
user ID that uniquely identifies
this device to Apptimize, or, in uncommon cases where there is no
user ID, either null
or the empty string.public static void setOnExperimentRunListener(Apptimize.OnExperimentRunListener l)
l
- The Apptimize.OnExperimentRunListener
that will be invoked when an Apptimize A/B test is run. If
this null
then any previously set listener will be
unset.public static void addOnExperimentsProcessedListener(Apptimize.OnExperimentsProcessedListener l)
l
- The Apptimize.OnExperimentsProcessedListener
that will be invoked when an Apptimize configuration is recalculated.public static void removeOnExperimentsProcessedListener(Apptimize.OnExperimentsProcessedListener l)
l
- The Apptimize.OnExperimentsProcessedListener
to be removed.public static void setTestmodeActive(boolean mode)
mode
- if true, this method will activate the test mode which overrides normal sdk behavior.
if false, this method will restore the sdk normal behaviorpublic static void setActiveCodeBlockForExperiment(java.lang.String experimentName, java.lang.String variationMethodName)
experimentName
- name of the experimentvariationMethodName
- the variation method name being appliedpublic static <T> void setActiveValueForDynamicVariable(ApptimizeVar<T> dynVar, T value)
dynVar
- the dynamic variablevalue
- the value of the dynamic variablepublic static void setCustomerUserId(java.lang.String customerUserId)
Set the current customer-specified user ID
User IDs are arbitrary strings, except that they cannot be the empty string "". When the customer-specified user ID is null, then Apptimize creates and uses an anonymous user ID for tracking purposes. If the customerUserId is set to a non-null value, then set back to null, Apptimize will use the same anonymous user ID as before. The initial default value of the customer-specified user ID is null.
customerUserId
- the user ID stringpublic static java.lang.String getCustomerUserId()
Get the current customer-specified userId
User IDs are arbitrary strings. If the customer-specified user ID is null, then Apptimize will create and use an anonymous user ID for tracking purposes. The initial default value of the customer-specified user ID is null.
public static java.lang.String getApptimizeAnonUserId()
Get the current Apptimize-created anonymous user ID
This anonymous user ID will be used if-and-only-if the customer-specified user ID is null. A single anonymous user ID is created. If the customerUserId is set to a non-null value, then set back to null, Apptimize will use the same anonymous user ID as before.