Class TreasureData

  • All Implemented Interfaces:
    CDPClient

    public class TreasureData
    extends java.lang.Object
    implements CDPClient
    • Constructor Detail

      • TreasureData

        public TreasureData​(android.content.Context context,
                            java.lang.String apiKey,
                            java.lang.String apiEndpoint)
    • Method Detail

      • initializeSharedInstance

        public static TreasureData initializeSharedInstance​(android.content.Context context,
                                                            java.lang.String apiKey,
                                                            java.lang.String apiEndpoint)
        Initialize shared instance with Treasure Data API key and API endpoint
        Parameters:
        apiKey - Treasure Data API key
        apiEndpoint - Treasure Data API key
        context - Context for Treasure Data shared instance
        Returns:
        sharedInstance()
      • initializeSharedInstance

        public static TreasureData initializeSharedInstance​(android.content.Context context,
                                                            java.lang.String apiKey)
        Initialize shared instance with Treasure Data API key and default API endpoint
        Parameters:
        apiKey - Treasure Data API key of default API endpoint. To set API endpoint, use initializeSharedInstance(Context, String, String)
        context - Context for Treasure Data shared instance
        Returns:
        sharedInstance()
      • initializeSharedInstance

        public static TreasureData initializeSharedInstance​(android.content.Context context)
      • sharedInstance

        public static TreasureData sharedInstance()
        The default singleton SDK instance.
        Returns:
        the shared instance
      • getApplicationContext

        public static android.content.Context getApplicationContext()
      • getExecutor

        public static java.util.concurrent.Executor getExecutor()
      • getUUID

        public java.lang.String getUUID()
        Get UUID generated from TreasureData. The value will be set to `td_uuid` column for every events if `enableAutoAppendUniqId` is called.
        Returns:
        UUID value
      • resetUniqId

        public void resetUniqId()
        Reset UUID and send forget_device_uuid event with old uuid
      • isFirstRun

        public boolean isFirstRun​(android.content.Context context)
      • clearFirstRun

        public void clearFirstRun​(android.content.Context context)
      • enableLogging

        public static void enableLogging()
        Enable client logging. Disabled by default.
      • disableLogging

        public static void disableLogging()
        Disable client's logging
      • initializeEncryptionKey

        public static void initializeEncryptionKey​(java.lang.String encryptionKey)
        Encrypts the event data in the local persisted buffer. This should be called only once and prior to any `addEvent...` call.
        Parameters:
        encryptionKey - encryption key to use
      • enableEventCompression

        public static void enableEventCompression()
        Event data will be compressed before uploading to server.
      • disableEventCompression

        public static void disableEventCompression()
        Event data will be uploaded in it's full format.
      • setDefaultDatabase

        public void setDefaultDatabase​(java.lang.String defaultDatabase)
        The destination database for events that doesn't specify one, default is "td".
        Parameters:
        defaultDatabase - name of the destination database
      • setDefaultTable

        public void setDefaultTable​(java.lang.String defaultTable)
        The destination table for events that doesn't specify one. Currently this also applied for automatically tracked events (if enabled): app lifecycle, IAP and audits, default is "td_android".
        Parameters:
        defaultTable - name of the destination table
      • setAddEventCallBack

        public void setAddEventCallBack​(TDCallback callBack)
        Set callback for when add event either succeed or fail.
        Parameters:
        callBack - callback to be invoked
      • getAddEventCallBack

        public TDCallback getAddEventCallBack()
        Get callback for when add event either succeed or fail if you had set one.
        Returns:
        callback to be invoked
      • setUploadEventsCallBack

        public void setUploadEventsCallBack​(TDCallback callBack)
        Set callback for when upload events either succeed or fail.
        Parameters:
        callBack - callback to be invoked
      • getUploadEventsCallBack

        public TDCallback getUploadEventsCallBack()
        Get callback for when upload events either succeed or fail if you had set one.
        Returns:
        callback to be invoked
      • setMaxUploadEventsAtOnce

        public void setMaxUploadEventsAtOnce​(int maxUploadEventsAtOnce)
        Set max number of records can be sent per upload events call.
        Parameters:
        maxUploadEventsAtOnce - number of maximum events
      • getMaxUploadEventsAtOnce

        public int getMaxUploadEventsAtOnce()
        Get max number of records can be sent per upload events call.
        Returns:
        number of maximum events
      • addEvent

        public void addEvent​(java.lang.String database,
                             java.lang.String table,
                             java.util.Map<java.lang.String,​java.lang.Object> record)
        Track a new event
        Parameters:
        database - the event's destination database
        table - the event's destination table
        record - event data
      • addEventWithCallback

        public void addEventWithCallback​(java.lang.String database,
                                         java.lang.String table,
                                         java.util.Map<java.lang.String,​java.lang.Object> origRecord,
                                         TDCallback callback)
        Track a new event
        Parameters:
        database - the event's destination database
        table - the event's destination table
        origRecord - event data
        callback - callback for when add event either succeed or fail. Default to setAddEventCallBack(TDCallback)
      • addEvent

        public void addEvent​(java.lang.String table,
                             java.util.Map<java.lang.String,​java.lang.Object> record)
        Track a new event to default database set by setDefaultDatabase(String)
        Parameters:
        table - the event's destination table
        record - event data
      • addEventWithCallback

        public void addEventWithCallback​(java.lang.String table,
                                         java.util.Map<java.lang.String,​java.lang.Object> record,
                                         TDCallback callback)
        Track a new event to default database set by setDefaultDatabase(String)
        Parameters:
        table - the event's destination table
        record - event data
        callback - callback for when add event either succeed or fail. Default to setAddEventCallBack(TDCallback)
      • uploadEventsWithCallback

        public void uploadEventsWithCallback​(TDCallback callback)
        Upload events with callback
        Parameters:
        callback - callback to be invoked
      • appendSessionId

        public void appendSessionId​(java.util.Map<java.lang.String,​java.lang.Object> record)
      • appendLocalTimeStamp

        public void appendLocalTimeStamp​(java.util.Map<java.lang.String,​java.lang.Object> record)
      • appendUniqId

        public void appendUniqId​(java.util.Map<java.lang.String,​java.lang.Object> record)
      • appendModelInformation

        public void appendModelInformation​(java.util.Map<java.lang.String,​java.lang.Object> record)
      • appendAppInformation

        public void appendAppInformation​(java.util.Map<java.lang.String,​java.lang.Object> record)
      • appendLocaleInformation

        public void appendLocaleInformation​(java.util.Map<java.lang.String,​java.lang.Object> record)
      • appendRecordUUID

        public void appendRecordUUID​(java.util.Map<java.lang.String,​java.lang.Object> record)
      • enableAppLifecycleEvent

        public void enableAppLifecycleEvent()
        Enable app lifecycle tracking. This setting has no effect to custom tracking
      • disableAppLifecycleEvent

        public void disableAppLifecycleEvent()
        Disable app lifecycle tracking. This setting has no effect to custom tracking
      • enableAppLifecycleEvent

        public void enableAppLifecycleEvent​(boolean enabled)
        Toggle app lifecycle tracking. This setting has no effect to custom tracking
        Parameters:
        enabled - true : enabled, false : disabled
      • isAppLifecycleEventEnabled

        public boolean isAppLifecycleEventEnabled()
        Whether or not the app lifecycle tracking is enabled
        Returns:
        true : enabled, false : disabled
      • enableInAppPurchaseEvent

        public void enableInAppPurchaseEvent()
        Enable tracking In App Purchase event automatically. This is disabled by default.
      • disableInAppPurchaseEvent

        public void disableInAppPurchaseEvent()
        Enable tracking In App Purchase event automatically. This is disabled by default.
      • enableInAppPurchaseEvent

        public void enableInAppPurchaseEvent​(boolean enabled)
        Toggle tracking In App Purchase event automatically. This is disabled by default.
        Parameters:
        enabled - true : enabled, false : disabled
      • isInAppPurchaseEventEnabled

        public boolean isInAppPurchaseEventEnabled()
        Whether or not the In App Purchase tracking is enabled
        Returns:
        true : enabled, false : disabled
      • enableCustomEvent

        public void enableCustomEvent()
        Enable custom event tracking.
      • disableCustomEvent

        public void disableCustomEvent()
        Disable custom event tracking.
      • isCustomEventEnabled

        public boolean isCustomEventEnabled()
        Whether or not the custom event tracking is enable
        Returns:
        true : enable, false : disabled
      • enableCustomEvent

        public void enableCustomEvent​(boolean enabled)
        Toggle custom event availability
        Parameters:
        enabled - true : enabled, false : disabled
      • fetchUserSegments

        public void fetchUserSegments​(java.util.List<java.lang.String> profilesTokens,
                                      java.util.Map<java.lang.String,​java.lang.String> keys,
                                      FetchUserSegmentsCallback callback)
        Specified by:
        fetchUserSegments in interface CDPClient
        Parameters:
        profilesTokens - list of Profile API Token that are defined on TreasureData
        keys - lookup keyColumn values
        callback - to receive the looked-up result
      • setDefaultValue

        public void setDefaultValue​(java.lang.String database,
                                    java.lang.String table,
                                    java.lang.String key,
                                    java.lang.Object value)
        Set default `value` for `key` in all new events targeting `database` and `table`. When `database` and/or `table` parameters are null, the null parameter acts like a wild card that allows to set specified key value pair to new events added to any database (if `database` is null) and/or to any table (if `table` is null). For example, if you pass null to both `database` and `table` parameters, all new events will have specified default value.
        Parameters:
        database - the database to set default value to. If null, specified table of any database will have new events with the added default value.
        table - the table to set default value to. If null, any table of specified database will have new events with the added default value.
        key - the event's key that default value is set to, corresponding to column in table.
        value - default value for `key`
      • getDefaultValue

        public java.lang.Object getDefaultValue​(java.lang.String database,
                                                java.lang.String table,
                                                java.lang.String key)
        Get default value of `key` in all new events targeting `database` and `table`. See setDefaultValue() for logic setting database and table.
        Parameters:
        database - the database to get default value from. If null, get default value of specified table of any database.
        table - the table to get default value from. If null, get default value of any table of specified database.
        key - the event's key that default value is set to, corresponding to column in table.
        Returns:
        default value for `key` for events targeting `database` and `table`.
      • removeDefaultValue

        public void removeDefaultValue​(java.lang.String database,
                                       java.lang.String table,
                                       java.lang.String key)
        Remove default value of `key` in all new events targeting `database` and `table`. See setDefaultValue() for logic setting database and table.
        Parameters:
        database - the database to remove default value from. If null, specified table of any database will have new events without the default value.
        table - the table to remove default value from. If null, any table of specified database will have new events without the default value.
        key - the event's key that default value is set to, corresponding to column in table.
      • disableAppInstalledEvent

        public void disableAppInstalledEvent()
        Disable automatic tracking of event when app is installed
      • disableAppUpdatedEvent

        public void disableAppUpdatedEvent()
        Disable automatic tracking of event when app is updated
      • disableAppOpenEvent

        public void disableAppOpenEvent()
        Disable automatic tracking of event when app is opened
      • disableAutoAppendUniqId

        public void disableAutoAppendUniqId()
        Disable the automatically appended `td_uuid` column.
      • enableAutoAppendUniqId

        public void enableAutoAppendUniqId()
        Automatically append `td_uuid` column for every events. The value is randomly generated and persisted, it is shared across app launches and events. Basically, it is used to represent for a unique app installation instance. This is disabled by default.
      • disableAutoAppendModelInformation

        public void disableAutoAppendModelInformation()
        Disable automatic tracking of model information
      • enableAutoAppendModelInformation

        public void enableAutoAppendModelInformation()
        Enable automatic tracking of model information
      • disableAutoAppendAppInformation

        public void disableAutoAppendAppInformation()
        Disable automatic tracking of app information
      • enableAutoAppendAppInformation

        public void enableAutoAppendAppInformation()
        Enable automatic tracking of app information
      • disableAutoAppendLocaleInformation

        public void disableAutoAppendLocaleInformation()
        Disable automatic tracking of locale information
      • enableAutoAppendLocaleInformation

        public void enableAutoAppendLocaleInformation()
        Enable automatic tracking of locale information
      • enableAutoAppendLocalTimestamp

        public void enableAutoAppendLocalTimestamp()
        Enable automatic tracking of local timestamp to `time` column. This is enabled by default
      • enableAutoAppendLocalTimestamp

        public void enableAutoAppendLocalTimestamp​(java.lang.String columnName)
        Enable automatic tracking of local timestamp with custom column name
        Parameters:
        columnName - custom column name
      • disableAutoAppendLocalTimestamp

        public void disableAutoAppendLocalTimestamp()
        Disable automatic tracking of local timestamp
      • enableAutoAppendAdvertisingIdentifier

        public void enableAutoAppendAdvertisingIdentifier()
        Enable automatic tracking of advertising identifier
      • enableAutoAppendAdvertisingIdentifier

        public void enableAutoAppendAdvertisingIdentifier​(java.lang.String columnName)
        Enable automatic tracking of advertising identifier with custom column name
        Parameters:
        columnName - column name for advertising id
      • disableAutoAppendAdvertisingIdentifier

        public void disableAutoAppendAdvertisingIdentifier()
        Disable automatic tracking of advertising identifier
      • disableAutoRetryUploading

        public void disableAutoRetryUploading()
        Disable automatic retry uploading. Once disabled, app will only attempt to upload events once per upload events call.
      • enableAutoRetryUploading

        public void enableAutoRetryUploading()
        Enable automatic retry uploading. Once enabled, app will keep retry to upload events until events are uploaded successfully.
      • setSessionTimeoutMilli

        public static void setSessionTimeoutMilli​(long timeoutMilli)
        Set the timeout in milliseconds. If startSession(Context) is called during this timeout after endSession(Context) is called. App will start session with the same id as previous one.
        Parameters:
        timeoutMilli - timeout duration in milliseconds
      • startSession

        public void startSession​(java.lang.String table)
        Add new start session event to specified table set in the params and default database set in setDefaultDatabase(String)
        Parameters:
        table - table to track session events
      • startSession

        public void startSession​(java.lang.String database,
                                 java.lang.String table)
        Add new start session event
        Parameters:
        database - database to track session events
        table - table to track session events
      • startSession

        public static void startSession​(android.content.Context context)
        Start tracking a global session
        Parameters:
        context - context of the global session
      • endSession

        public void endSession​(java.lang.String table)
        Add new end session event to specified table set in the params and default database set in setDefaultDatabase(String)
        Parameters:
        table - table to track session events
      • endSession

        public void endSession​(java.lang.String database,
                               java.lang.String table)
        Add new end session event
        Parameters:
        database - database to track session events
        table - table to track session events
      • endSession

        public static void endSession​(android.content.Context context)
        End tracking global session
        Parameters:
        context - context of the global session
      • getSessionId

        public java.lang.String getSessionId()
        Get current session id
        Returns:
        current session id
      • getSessionId

        public static java.lang.String getSessionId​(android.content.Context context)
        Get current global session id
        Returns:
        current global session id
      • resetSessionId

        public static void resetSessionId​(android.content.Context context)
        Reset global session id immediately
      • enableAutoAppendRecordUUID

        public void enableAutoAppendRecordUUID​(java.lang.String columnName)
        Automatically append a random and unique ID for each event. Disabled by default.
        Parameters:
        columnName - The column to write the ID
      • disableAutoAppendRecordUUID

        public void disableAutoAppendRecordUUID()
        Disable appending ID for each event.