• Platforms
  • Partners
  • Forums
  • TLC Tealium Learning Center Tealium Learning
    Community
  • Discussions & Ideas Dicussions & Ideas
  • Product Guides Product Guides
  • Knowledge Base Knowledge Base
  • Developer Docs Developer Docs
  • Education Education
  • TLC Blog TLC Blog
  • Support Desk Support Desk
  • CDH Customer Data Hub Customer Data Hub

Table of Contents

  • Class: Tealium
    • cancelTimedEvent()
    • consentManager
    • dataLayer
    • endTraceVisitorSession()
    • events
    • joinTrace()
    • leaveTrace()
    • modules
    • sendQueuedDispatches()
    • session
    • startTimedEvent()
    • stopTimedEvent()
    • Tealium
    • track()
    • visitorId
ANDROID KOTLIN

Tealium

Reference guide for Tealium class and methods provided by Tealium for Android (Kotlin).

Class: Tealium

The Tealium class provides methods for tracking screen views and events. The following document summarizes the commonly used methods and properties of the Tealium class for Kotlin. Individual modules may also provide their own extensions for the Tealium class if they are enabled.

Method/Property Description
cancelTimedEvent() Cancels the timer for a timed event
consentManager Access to the Consent Manager in order to set the user consent preferences
dataLayer Access to persistent storage on the device - items within the data layer are added to each event
endTraceVisitorSession() Ends the visitor session remotely to test end of session events
events Allows you to provide listener classes to a numerous events throughout the Tealium SDK
joinTrace() Adds the supplied trace ID to the data layer for the current session
leaveTrace() Leaves the trace by removing the trace ID
modules Provides access to the modules within the system
sendQueuedDispatches() Requests that any DispatchValidators be re-evaluated
session Provides information relating to the current session
startTimedEvent() Starts a timed event with the given name
stopTimedEvent() Stops the timer for a timed event which triggers the timed_event tracking call
Tealium Constructor method that creates a Tealium instance
track() Method for tracking your Screen Views or Events
visitorId The current Visitor ID that is stored in the data layer

cancelTimedEvent()

Cancels a previously started timed event. The timed event is not tracked.

tealium.cancelTimedEvent(name: "TIMED_EVENT_NAME")
Parameters Type Description
name String The name of the timed event

consentManager

Allows you to set your current consent status and categories, and see the current policy enforced. Learn more in the Consent Management guide.

tealium.consentManager.userConsentStatus = ConsentStatus.CONSENTED

dataLayer

Provides persistent storage on the device for key-value pairs, while also allowing you to set expiry times. Each entry is also added to every dispatch that you send through the track() method. Learn more in the Data Management guide.

tealium.dataLayer.putString("key", "value", Expiry.FOREVER)

endTraceVisitorSession()

Ends the visitor session remotely. Does not terminate the SDK session or reset the session ID.

Tealium["INSTANCE_NAME"]?.endTraceVisitorSession()

events

Provides listener classes to your Tealium instance in order to receive useful information from the SDK.

The following example registers a listener for any consent preference changes. This listener is provided with the new consent preferences and the current policy enforced. Additional listeners available at com.tealium.core.messaging.

tealium.events.subscribe(object: UserConsentPreferencesUpdatedListener {
    override fun onUserConsentPreferencesUpdated(userConsentPreferences: UserConsentPreferences, policy: ConsentManagementPolicy) {
        // take action on consent changes
    }
})

joinTrace()

Adds the supplied trace ID to the data layer for the current session.

Tealium["INSTANCE_NAME"]?.joinTrace(traceId)
Parameters Type Description
traceId String Trace ID

leaveTrace()

Leaves the trace by removing the trace ID.

Tealium["INSTANCE_NAME"]?.leaveTrace()

modules

Provides access to the Module Manager for the SDK, and used to provide access to specific modules.

tealium.modules.getModule(VisitorService::class.java)?.delegate = myDelegate

sendQueuedDispatches()

Dispatches are queued for a number of reasons by any DispatchValidator. You may request that they be re-evaluated using this method which ignores the event batching restrictions, but adheres to other DispatchValidators. For example, if there was no connectivity and there is still no connectivity then queued dispatches remain queued.

tealium.sendQueuedDispatches()

session

Contains all data relating to the current Session.

val sessionId = tealium.session.id

startTimedEvent()

Starts a timed event with the given name. If this method is called again with the same event name, it is ignored if the event has not been ended or canceled. The event start time is not persisted.

If optional data is passed along with the event name, it is added to the track call when the timer is stopped with the stopTimedEvent() call.

tealium.startTimedEvent(name: "TIMED_EVENT_NAME", mapOf("custom_value" to "custom_key"))
Parameters Type Description
name String The name of the timed event
mapOf("custom_key" to "custom_value") Map (Optional) An object of key-value pair data to be tracked in the data layer

stopTimedEvent()

Stops the timer for a timed event which triggers the timed_event tracking call.

tealium.stopTimedEvent(name: "TIMED_EVENT_NAME")
Parameters Type Description
name String The name of the timed event

Tealium

Constructor method that creates a Tealium instance.

val config = TealiumConfig(key, config);
Parameters Type Description Example
key String New Tealium instance name "abc123"
config Tealium.Config The configuration for the new instance tealConfigObj
// Assuming execution is within Application.onCreate()
val config = TealiumConfig(this, "ACCOUNT_NAME", "PROFILE_NAME", Environment.PROD)
val tealium = Tealium.create("main", config)

Modules are initialized on a background Thread and therefore may not be ready directly after creation of the Tealium object. Add a completion block in order to add any subsequent required configuration as soon as the instance is ready:

val tealium = Tealium.create("main", config) {
    events.subscribe(object : VisitorUpdatedListener {
        override fun onVisitorUpdated(visitorProfile: VisitorProfile) {
            Logger.dev("--", "VisitorProfile updated: $visitorProfile")
        }
    })
}

track()

The method used for tracking events within the system such as screen views and events.

tealium.track(TealiumView("SCREEN_NAME", mapOf("key" to "context value")))

visitorId

The current String for the Visitor ID. It is stored within the data layer, and may be overridden if required.

val visitorId = tealium.visitorId
LocationManager
TealiumConfig

 
  • Mobile
  • Getting Started
    • Overview
    • Quick Start Guide
    • Mobile Concepts
    • Client-Side
    • Server-Side
    • Tracking Webviews
    • Data Layer
    • Consent Management
    • Event Batching
    • User Location and Geofencing
    • Deep Links
    • Timed Events
    • Trace
    • Hosted Data Layer
    • Feature Comparison
    • Troubleshooting
  • Remote Commands
    • Overview
    • How It Works
    • Integrations
      • AppsFlyer
      • Braze
      • Contentsquare
      • Facebook
      • Firebase
      • Kochava
      • Usabilla
  • Android (Java)
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • Consent Management
    • Module List
      • Ad Identifier Module
      • Crash Reporter Module
      • Install Referrer Module
      • Lifecycle Tracking Module
      • Location Module
      • Optimizely X Tracking Module
    • Android TV
    • Android Wear
    • API Reference
      • ConsentManager
      • DataSources
      • Lifecycle
      • Tealium
      • Tealium.Config
      • TealiumLocation
    • Release Notes
  • Android (Kotlin)
    • Overview
    • Install
    • Track
    • Data Layer
    • Consent Management
    • Identity Resolution
    • Module List
      • Ad Identifier Module
      • Collect Module
      • Collectors Module
      • Crash Reporter Module
      • Install Referrer Module
      • Lifecycle Tracking Module
      • Location Manager Module
      • RemoteCommands Module
      • Tag Management Dispatcher Module
      • Visitor Service Module
    • Android TV
    • API Reference
      • ConsentCategory
      • ConsentManager
      • CurrentVisit
      • DataLayer
      • Lifecycle
      • LocationManager
      • Tealium
      • TealiumConfig
      • VisitorProfile
      • VisitorService
    • Release Notes
  • Cordova
    • Overview
    • Install
    • Track
    • Data Management
    • Module List
      • Ad Identifier Module
      • Crash Reporter Module
      • Install Referrer Module
    • API Reference
    • Release Notes
  • Flutter
    • Overview
    • Install
    • Track
    • Consent Management
    • Data Management
    • API Reference
    • Release Notes
  • iOS (Objective-C)
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • Consent Management
    • Tag Management
    • Module List
      • Lifecycle Tracking Module
    • tvOS
    • watchOS
    • API Reference
    • Release Notes
  • iOS (Swift) 1.x
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • App Extensions
    • Identity Resolution
    • Consent Management
    • Modules
    • Module List
      • AppData Module
      • Attribution Module
      • AutoTracking Module
      • Collect Module
      • Connectivity Module
      • CrashReporter Module
      • DataSource Module
      • DefaultStorage Module
      • Delegate Module
      • DeviceData Module
      • DispatchQueue Module
      • FileStorage Module
      • Lifecycle Module
      • Location Module
      • Logger Module
      • PersistentData Module
      • RemoteCommands Module
      • TagManagement Module
      • VisitorService Module
      • VolatileData Module
    • Feature Comparison
    • Working with Objective-C
    • API Reference
      • TealiumConfig
      • TealiumConsentCategories
      • TealiumConsentManagerDelegate
      • TealiumConsentManager
      • TealiumInstanceManager
      • TealiumPersistentData
      • TealiumVolatileData
      • Tealium
    • Release Notes
  • iOS (Swift) 2.x
    • Overview
    • Install
    • Track
    • Data Layer
    • Consent Management
    • App Extensions
    • Identity Resolution
    • Modules
    • Module List
      • AppData Module
      • Attribution Module
      • AutoTracking Module
      • Collect Module
      • Connectivity Module
      • CrashReporter Module
      • DeviceData Module
      • Lifecycle Module
      • Location Module
      • RemoteCommands Module
      • TagManagement Module
      • VisitorService Module
    • Working with Objective-C
    • API Reference
      • Tealium
      • TealiumConfig
      • TealiumConsentCategories
      • TealiumConsentManager
      • TealiumDataLayer
      • TealiumInstanceManager
    • Release Notes
  • NativeScript
    • Overview
    • Install
    • Track
    • API Reference
      • Tealium
      • TealiumConfig
    • Release Notes
  • React Native 1.x
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • React Native 2.x
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • Unity
    • Overview
    • Install
    • Track
    • API Referencee
  • Xamarin
    • Overview
    • Install
    • Track
    • Data Management
    • Consent Management
    • API Reference
    • Release Notes
  • Web
  • Getting Started
    • Overview
    • Quick Start Guide
    • Web Concepts
  • Adobe Launch
    • Overview
    • Install
    • Data Layer
  • AMP
    • Install
    • Track
    • Data Layer
    • Overview
  • Angular
    • Install
    • Track
    • API Reference
    • Overview
  • Google Tag Manager
    • Overview
    • Data Layer
    • Install
  • JavaScript (Web)
    • Install
    • Track
    • Data Layer
    • Overview
    • Universal Data Object (utag_data)
    • Universal Tag (utag.js)
    • Data Layer Object (b)
    • Single-Page Applications
    • Settings
    • Debugging
    • API Reference
      • Cookie Functions
      • GDPR Functions
      • Tracking Functions
      • Utility Functions
    • Release Notes
  • Server
  • C#
    • Overview
    • Install
    • Track
    • Data Layer
    • API Reference
    • Release Notes
  • HTTP API
    • Overview
    • Endpoint
    • Data Layer
  • Java
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • Node
    • Overview
    • Install
    • Track
    • API Reference
  • Python
    • Overview
    • Install
    • Track
    • API Reference
  • Roku
    • Overview
    • Install
    • Track
    • API Reference
  • Ruby
    • Overview
    • Install
    • Track
    • API Reference

Was this article helpful?

This page was last updated: December 9, 2020       Thank you for your feedback!
  • Platforms
  • Partners
  • Forums
  • Mobile
  • Getting Started
  • Remote Commands
  • Android (Java)
  • Android (Kotlin)
  • Cordova
  • Flutter
  • iOS (Objective-C)
  • iOS (Swift) 1.x
  • iOS (Swift) 2.x
  • NativeScript
  • React Native 1.x
  • React Native 2.x
  • Unity
  • Xamarin
  • Web
  • Getting Started
  • Adobe Launch
  • AMP
  • Angular
  • Google Tag Manager
  • JavaScript (Web)
  • Server
  • C#
  • HTTP API
  • Java
  • Node
  • Python
  • Roku
  • Ruby